Forum Moderators: coopster
<?php
$string ="a99b";
$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);
print $substr2;
?>
$string = 'aaa12345vvvv';
$string = preg_replace('/[^\d]+/','',$string);
echo $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
123456789