我有preg_match
只匹配一次出现
preg_match('/(\$[0-9,]+(\.[0-9]{2})?)/', $lines[0], $match);
以下是数据:
<strong>Apr- May Price: </strong>Adult: $2,999.00 Children: $2,249.00 <br />
当我在print_r
上$match
时,我得到以下内容
Array ( [0] => $2,999.00 [1] => $2,999.00 [2] => .00 )
我应该将$2,999.00
和$2,249.00
存储在$match
答案 0 :(得分:4)
您需要改为使用preg_match_all。
$string = '<strong>Apr- May Price: </strong>Adult: $2,999.00 Children: $2,249.00 <br />';
preg_match_all('/(\$[0-9,]+(\.[0-9]{2})?)/', $string, $match);
var_dump($match);
:
array(3) {
[0]=>
array(2) {
[0]=>
string(9) "$2,999.00"
[1]=>
string(9) "$2,249.00"
}
[1]=>
array(2) {
[0]=>
string(9) "$2,999.00"
[1]=>
string(9) "$2,249.00"
}
[2]=>
array(2) {
[0]=>
string(3) ".00"
[1]=>
string(3) ".00"
}
}