【发布时间】:2016-06-27 17:46:23
【问题描述】:
我在 if 语句中有 2 个 preg_match,并且 if 其中任何一个都是正确的,我想将它们都打印出来。但是由于某种原因,每次只匹配第一个preg_match,即使它们都具有相同的模式。为什么会这样?
<?php
$string = "how much is it?";
if (preg_match("~\b(how (much|many))\b~", $string, $match1) || preg_match("~\b(how (much|many))\b~", $string, $match2)) {
print_r($match1);
print_r($match2);
}
?>
结果:
Array ( [0] => how much [1] => how much [2] => much )
预期结果:
Array ( [0] => how much [1] => how much [2] => much )
Array ( [0] => how much [1] => how much [2] => much )
【问题讨论】:
标签: php preg-match