分隔符 - 我将eregi更改为preg_match

时间:2012-03-13 18:21:57

标签: php preg-match

我有问题 - 分隔符不能是字母数字或反斜杠 我将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; }

2 个答案:

答案 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)