开发者

PHP String Parsing

开发者 https://www.devze.com 2022-12-17 21:58 出处:网络
I have string wh开发者_如何学Goich contains something about \"amount 3 val 6, amount 7 val 8\" and so, what regular expression should I use to get array with corresponding amounts and values?$str = \"

I have string wh开发者_如何学Goich contains something about "amount 3 val 6, amount 7 val 8" and so, what regular expression should I use to get array with corresponding amounts and values?


$str = "amount 3 val 6, amount 7 val 8";
preg_match_all('~amount (\d+) val (\d+)~i', $str, $matches);

echo '<pre>';
print_r($matches);
echo '</pre>';


$str = 'amount 3 val 6, amount 7 val 8';
preg_match_all('#amount\s+(\d+)\s+val\s+(\d+)#', $str, $matches);

All amounts in $matches[1], all vals in $matches[2].


amount\s*(\d*)\s*val\s*(\d*)

You can do the rest

0

精彩评论

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

关注公众号