在多个模式的情况下,可以在相同的数组索引下返回preg_match的结果。我的意思是,我有下面的preg_match,用来检查不同的子串('&q','?q','&keywords')。
preg_match('/&q=(.+?)(&|$)|\?q=(.+?)(\&|$)|\&keywords=(.+?)(\&|$)/', urldecode($test_string), $matches); 我希望看到$matches[1]下的所有事件都可以排除以下if语句。
if($matches){
if ($matches[1] != ''){
$query_p = mysql_escape_string($matches[1]);
} elseif ($matches[3] != ''){
$query_p = mysql_escape_string($matches[3]);
} elseif($matches[5] != ''){
$query_p = mysql_escape_string($matches[5]);
}
}发布于 2012-12-17 16:58:40
https://stackoverflow.com/questions/13910929
复制相似问题