function check_this_out($arg) { return "<a href='#'>$arg</a>"; }
$myString = 'hello';
$pattern = '/(.*)/e'; $replacement = "check_this_out('\\1' . ' $myString')"; echo preg_replace($pattern, $replacement, 'test says:');
[EMAIL PROTECTED] wrote:
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, [EMAIL PROTECTED] (John W. Holmes) wrote:
From: "Jochem Maas" <[EMAIL PROTECTED]>
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...
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php