Page 1 of 1

preg_match(): Unknown modifier problem

Posted: Mon Jul 27, 2009 8:57 am
by bobb
I have this code (a small piece of a total):

Code: Select all

 
<?
//...
$_getwebbot['SharpReader'] = "SharpReader[ /]([0-9.]{1,10})";
$_getwebbot['SherlockSpider'] = "sherlock_spider";
//...
?>

I check a string with these values as following:

Code: Select all

<?
while(list($name,$ereg) = each($_getwebbot)){
 
               
                if(preg_match('_'.$ereg.'_', $user_agent)){
               
 
                $webbot = $name;
                   
 
                break;
 
                }
                echo "<br>".$ereg;
}?>


As output I get:
...
SharpReader[ /]([0-9.]{1,10})
Warning: preg_match(): Unknown modifier 'p' in value.class.php on line 39

sherlock_spider
...

What am I doing wrong? I don't see it... I don't get this error with every line (I mean every $_getwebbot['']=) but just with specific items like sherlock_spider...

Re: preg_match(): Unknown modifier problem

Posted: Mon Jul 27, 2009 9:04 am
by jackpf
You need to escape the underscore in sherlock_spider since you're using underscores as your delimiters.

Re: preg_match(): Unknown modifier problem

Posted: Mon Jul 27, 2009 9:16 am
by bobb
Thanks, I used # instead of _ and it worked!

Re: preg_match(): Unknown modifier problem

Posted: Mon Jul 27, 2009 9:23 am
by jackpf
...or you could use a different modifier like you have done :P

Cool.