开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜