| Welcome to WebmasterWorld Guest from 184.108.40.206 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Pubcon Platinum Sponsor 2014|
|search for string within a string using positions|
say i have a string like the following:
how can i extract just 999 here?
tried many fucntions but still no luck.thanks in advance!
oh by the way the length of the numeric part changes. so it can be 1 to n
sorry for postin again. to mk things easier i'v made the string as follows.
so i want to know how can i get the string in between the character 'c' and 'd'.
made this ma self. in case anyone needs here it is:
$start = strpos($string, "a");
$end = strpos($string, "b");
$length = strlen($string);
print "the start is ".$start." end is ".$end." the total length".$length."<br />";
$substr1 = substr($string, $start+1, $length);
print $substr1."<br />";
$new_length = strlen($substr1);
$num = $new_length-1;
//new length is 3
$substr2 = substr($substr1, -$new_length, $num);
Glad you got it sorted, but let me ask: are you after only the numeric part of this string?
$string = 'aaa12345vvvv';
$string = preg_replace('/[^\d]+/','',$string);
Basically this regexp says "replace one or more characters not (^) a digit with nothing."
This many have an unexpected result if the strings are not in the format you posted,
$string = 'aaa12345vv6789vv';
will result in
in my case i jst want 12345. so thats why i basically tried to get the values between aaa and vv(in ur example). thanks for the post
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved