例如:
$str .= "Additional tax(2.34)";
$str .= "Additional tax(3)";
任何人都可以帮助我从字符串中提取数字。我需要像这样的数组格式
Array ( [0] => 2.34 [1] => 3 );
答案 0 :(得分:7)
这应该这样做:
<?php
$str = '';
$str .= "Additional tax(2.34)";
$str .= "Additional tax(3)";
if (preg_match_all('/\((\d+(?:\.\d+)?)\)/', $str, $matches) > 0) {
var_dump($matches[1]);
}
?>