Re: Re: preg_replace

From: Date: Mon, 17 Jun 2002 01:04:08 +0000
Subject: Re: Re: preg_replace
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-102443@lists.php.net to get a copy of this message
I still needed to drop the '=' chars, so here is the modified version Thanks for your help preg_replace('/(=)([A-Z0-9_]+)(=)/e', 'constant("$2")', $foo); CC Zona wrote:
In article <3D0CC9BB.1080302@trini0.org>, gsam@trini0.org (Gerard Samuel) wrote:
When you think you got it, you don't get it.. Im trying to scan the link for =A-Z0-9_=, dump the '=' and evaluate the remainder as a defined constant. Yes its funny looking, but if I could get this going Im golden. $bar is always returned with '=_L_OL_HERE=' as the link and not 'here' as it supposed to be. Any help would be appreciated. Thanks <?php define('_L_OL_HERE', 'here'); $foo = '<a href="there.com">=_L_OL_HERE=</a>'; $bar = preg_replace('/(=)([A-Z0-9_])(=)/e', ' . constant("$2") . ', $foo); echo $bar; ?>
You're trying to match one or more characters in the class, so add a "+". And you're not concatenating the expression 'constant("$2")' with anything, so lose the extra periods. Parentheses aren't needed around the equals signs, so you might as well drop those too. Ex: preg_replace('/=([A-Z0-9_]+)=/e', 'constant("$1")', $foo);
-- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/

« previous php.general (#102443) next »