$item
中有一个/
,这意味着它认为,正则表达式结束早于它。
/goldfish/herring/
// ^Not actually a modifier (h) - just an unescaped string
可以使用preg_quote($string, '/')
功能即可关闭此为以下:
/goldfish\/herring/
// ^Escaped
使用:
foreach($items as $k=>$item){
if($item!='' && preg_match("/".preg_quote($item,"/")."/", $opText)){
if(!in_array($item,$params[$val['name']],true)){
$params[$val['name']][]=$item;
}
}
}
提示:
我F该是硬编码的正则表达式,你可以改变你的转义字符,使正则表达式更容易不必逃避常用字符阅读:
~goldfish/herring~
// ^ ^
// | \- Using a different modifier
// |
// \- Different from the modifier, so we don't have to escape it
最有可能'$ item'包含了'/'然后是'h'。 –