Re: Regular expressions
| From: | pete at doberad dot com | Date: | Tue, 03 Feb 2004 21:26:46 +0000 |
| Subject: | Re: Regular expressions | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-176732@lists.php.net to get a copy of this message | ||
Thank you very much Jochem and John. It works like a charm now, and I
was beginning to grow weary after experimenting with result sets for
almost 10 hours now.
How would you - by the way - concatenate text to the replacement
string?
;-Pete
On Tue, 3 Feb 2004 14:15:00 -0500, holmes072000@charter.net (John W.
Holmes) wrote:
>From: "Jochem Maas" <jochem@iamjochem.com>
>
>> alternatively (actually this looks like the easier way to do it!) use
>> preg_replace(), with the 'e' modifier tagged onto the end of the
>> replacement expression: the 'e' modifier causes the expression to be
>> evaluated as PHP.
>>
>> http://nl2.php.net/manual/en/function.preg-replace.php
>> http://nl2.php.net/manual/en/pcre.pattern.modifiers.php
>>
>> something like:
>>
>> $pattern = '/\[link="([[:graph:]]+)"]/';
>> $replacement = "/check_this_out('\1')/e";
>> $output = preg_replace($pattern, $replacement, $output);
>
>Good idea, except the "e" modifier goes in the pattern, not the replacement.
>And you don't need delimiters in the replacement.
>
>$pattern = '/\[link="([[:graph:]]+)"]/e';
>$replacement = "check_this_out('\1')";
>$output = preg_replace($pattern, $replacement, $output);
>
>---John Holmes...