Re: Regular expressions

From: Date: Tue, 03 Feb 2004 19:15:00 +0000
Subject: Re: Regular expressions
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-176718@lists.php.net to get a copy of this message
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=&quot;([[:graph:]]+)&quot;]/'; > $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=&quot;([[:graph:]]+)&quot;]/e'; $replacement = "check_this_out('\1')"; $output = preg_replace($pattern, $replacement, $output); ---John Holmes...

« previous php.general (#176718) next »