php正则表达式提取数字,字符串中提取数字
php正则表达式提取数字,字符串中提取数字
<?php
$str = "请注意:有谁知道30901.5号路怎么走?这个因为我买了100块的烧饼和7901的钥匙了,那个对了,我再拿个30000";
$pattern = '/(\d+\.?\d+)/';
//$pattern = '/(\d+)\.?(\d+)/';
// $str = "42.234 EUR 53.218 AUD CAD97.164 311.151 MYR 125.042 NZD GBP84.270 SGD60.227 USD134.400";
if(preg_match_all($pattern, $str, $match)){
echo '<pre>';
print_r($match);
}else{
echo '没有找到!';
}
?>
结果
Array
(
[0] => Array
(
[0] => 30901
[1] => 100
[2] => 7901
[3] => 30000
)
[1] => Array
(
[0] => 30901
[1] => 100
[2] => 7901
[3] => 30000
)
)
转载于:https://www.cnblogs.com/bluealine/p/11152412.html
参考 https://blog.csdn.net/ak47147258369/article/details/101984718?o