note 25869 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 22:05:04 +0000
Subject: note 25869 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55699@lists.php.net to get a copy of this message
Note Submitter: yvesb at active dot ch ---- I recently run into a problem which I still dont understand. Assuming that you have a text-string which has been read from a file. This text-string contains mainly HTML and some $$(w+)$$-kind-of character combinations, which should be substituted by scalars using a php script. Now what I tried is the following: preg_replace("/\\\$\\\$(\w+)\\\$\\\$/", "$GLOBALS[$1]", $Data) yet for some reason that eludes me, $GLOBALS[$1] as well as $GLOBALS[\\1] causes an error. Long time after I figured out that the following works: preg_replace("/\\\$\\\$(\w+)\\\$\\\$/e", "\$GLOBALS['\\1']", $Data) (Notice the /e in the preg_replace) Yet I am not really satisfied with this solution because I wanted to avoid /e. Maybe someone can give me a clue on this one and hopefully there are some others who find this useful.

« previous php.notes (#55699) next »