我有问题 - 分隔符不能是字母数字或反斜杠 我将eregi更改为preg_match PHP 5.3
$noCount=0;
for($i=0; $i<count($robotsIP); $i++){
if(preg_match($robotsIP[$i], $user_ip) || $user_ip==$robotsIP[$i]){ $noCount=1; $robot = 1; }
}
if(trim($user_ip)==''){ $noCount=1; $robot = 1; }
答案 0 :(得分:1)
嗯,如果您向我们展示$robotsIP
数组中的值的示例,可能会有所帮助。
无论如何,听起来你的字符串中没有分隔符。 preg_*
正则表达式需要由第一个字符定义的分隔符。它们可以是任何非字母数字字符(在正则表达式中没有特殊含义吗?),但大多数人使用/
或有时我见过@
,特别是如果正则表达式本身需要包含/
s。例如:
preg_match("/fo{2}ba+r/", $str);
preg_match("@fo{2}ba+r@", $str);
答案 1 :(得分:0)
我猜可能会改变这一点
if(preg_match($robotsIP[$i], $user_ip)
到
if(preg_match("/".$robotsIP[$i]."/", $user_ip)