2012-03-13 54 views
-2

我有问题 - 分隔符不能是字母,数字或反斜线 我改变eregi到的preg_match PHP 5.3分隔符 - 我改变eregi到的preg_match

$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

我猜可能是修改该位

if(preg_match($robotsIP[$i], $user_ip) 

if(preg_match("/".$robotsIP[$i]."/", $user_ip) 
+0

THX,这段代码是正确的:) – ajuzo 2012-03-14 00:20:18

1

那么,它可能会帮助,如果你告诉我们的例子在th值e $robotsIP数组。

无论如何,它听起来像你没有在你的字符串中的分隔符。 preg_*正则表达式需要由第一个字符定义的分隔符。它们可以是任何非字母数字字符(它在正则表达式中没有特殊含义?),但大多数人使用/或有时我见过@,尤其是如果正则表达式本身需要包含/ s。例如:

preg_match("/fo{2}ba+r/", $str); 
preg_match("@fo{2}[email protected]", $str);