Re: preg_replace_callback clarification
| From: | François Moreau | Date: | Thu, 09 Sep 2004 14:14:35 +0000 |
| Subject: | Re: preg_replace_callback clarification | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196219@lists.php.net to get a copy of this message | ||
Thank you very much for your quick answer!
Le 04-09-09, à 10:10, John Holmes a écrit :
From: "François Moreau" <phpfrancois@grillonweb.com>The piece of code you have submitted (see under) is interesting, although there is one thing I don't find meaning to, even after RTFM, and STFG(Searching The Funky Google). In your regular expression pattern '#<b>.*</b>#Uis', what does this do : #...#Uis[snip]$new_str = preg_replace_callback('#<b>.*</b>#Uis','myreplace',$str);The # characters simply start and end the pattern. You can use any character for that, really. I normally use /, but since it's present in the pattern "</b>" and I didn't want to escape it, I used the # character. The characters after the pattern delimiters are called pattern modifiers. They are explained here (http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php), but for the afraid-to-clicky-people: U - ungreedy (makes sure the .* in the pattern doesn't match too much) i - case-insensitive matching (in case you use <B> and </B>) s - makes the dot character match newlines as well, otherwise text between bold tags that included newlines wouldn't be matches. ---John Holmes...