php - Extract first number(s) from variable -
i have variables start number or numbers , need script determine number ends, example variable can following:
1234-hello1.jpg
1 hello1.gif
1234hello1.gif
123456 hello1.gif
what trying explode function not work, , regex poor, need left first number , ignore other number in string. need left number(s) in bold.
thanks in advance...
$arr = str_split($str); for($i = 0; $i < count($arr); ++$i){ if(!is_numeric($arr[$i])){ echo "number ends @ index: " . $i; break; } }
you put numbers array using $arr[$i] if wish. lot more readable using regex.
you add logic allow 1 decimal point question seems want integers.
http://sandbox.onlinephpfunctions.com/code/fd21437e8c1502b56572a624cf6e4683cf483a8d - example of working code
Comments
Post a Comment