preg_match(): Unknown modifier problem

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
bobb
Forum Newbie
Posts: 18
Joined: Sun Jun 28, 2009 3:41 am

preg_match(): Unknown modifier problem

Post 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...
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: preg_match(): Unknown modifier problem

Post by jackpf »

You need to escape the underscore in sherlock_spider since you're using underscores as your delimiters.
bobb
Forum Newbie
Posts: 18
Joined: Sun Jun 28, 2009 3:41 am

Re: preg_match(): Unknown modifier problem

Post by bobb »

Thanks, I used # instead of _ and it worked!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: preg_match(): Unknown modifier problem

Post by jackpf »

...or you could use a different modifier like you have done :P

Cool.
Post Reply