0

例如:

$str .= "Additional tax(2.34)";
$str .= "Additional tax(3)";

谁能帮我从字符串中提取数字。我需要这样的数组格式

Array ( [0] => 2.34 [1] => 3 );
4

1 回答 1

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]);
    }
?>
于 2013-02-04T13:05:55.067 回答