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.

Written on December 11th, 2007 , Informative

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

SirSpanky.com – The Secret Diary of James Pearce Aged 20-Something is proudly powered by WordPress and the Theme Adventure by Eric Schwarz
Entries (RSS) and Comments (RSS).

SirSpanky.com – The Secret Diary of James Pearce Aged 20-Something

Personal jorunal of a professional geek – James Pearce in Perth, Australia