website tracking
Logo
Japan
 
My Photo
Name: James Pearce
Location: Perth, WA, Australia

Powered by Blogger

When using Perl style regular expressions in PHP, the preg_match function takes the whole pattern with delimiters as the pattern argument. E.g. you pass the string "/matched/" as the pattern. So this means, in theory, you can use match modifiers like this: "/matched/i" for case insensitive matching.
Now, when I was doing some regex work in PHP I had a string that contained multiple matches. I knew this, but it was only storing the first match in the $matches array. In Perl, this would be because you need to enable the global match modifier: "/matched/g". But the g modifier is not valid in PHP. What you need to do to obtain the same behaviour in PHP is use the preg_match_all function instead of preg_match. This enables the global match modifier.

0 Comments:

Post a Comment

<< Home