You can use preg_match to pull out the number from a string. As shown below:
$regex = "/\d*\.?\d+/";
preg_match($regex,$string,
echo $matches[0]; //contains the number
examples:
$string = "$456.12%moAB"; // $matches[0] = 456.12
$string = "slfkjsdlk$456%moABfsadfsd
$string = "XX456.XXX"; //matches[0] = 456
$string = "XXX0.456XXX"; //matches[0] = 0.456
$string = "XXX.456XXX"; //matches[0] = .456
I hope this does what you want, good luck
Main Topics
Browse All Topics





by: RoonaanPosted on 2005-10-31 at 11:16:27ID: 15195371
preg_replace is better than ereg_replace in terms of efficiency and speed:
$string);
The next line filters all but numbers and the dot sign.
$string = preg_replace('/[^0-9\.]/',
-r-