I'm wondering how to extract numbers from a string for example
$string = "1.8 to 250"
What i want to get is,
$a = 1.8
$b = 250
Thanks for any help provided
I'm wondering how to extract numbers from a string for example
$string = "1.8 to 250"
What i want to get is,
$a = 1.8
$b = 250
Thanks for any help provided
Try this :
$str = '1.8 to 250';
preg_match_all('!\d+!', $str, $matches);
print_r($matches);
From this post Extract numbers from a string
Try this:
$str = '1.8 to 250';
$string = explode(" ",$str);
//print_r($string);
for($i = 0;$i < count($string);$i++){
if(is_numeric($string[$i])){
print "\n $string[$i]";
}
}