PHP/regex - get certain number from a string
Need quick help with regexp, to search a string for
blah blah blah price 开发者_开发百科4.000 blah blah
and assign 4.000 or whatever number comes after price to a variable.
preg_match('~price\s+(\S+)~', $input, $matches);
var_dump($matches);
$num = preg_replace('/price ([\d,\.]+)/', '\1', $string);
or
preg_match('/price ([\d,\.]+)/', $string, $matches);
$num = $matches[1];
精彩评论