note 25869 added to function.preg-replace
| From: | yvesb at rack1 dot php dot net | Date: | Wed, 09 Oct 2002 13:58:14 +0000 |
| Subject: | note 25869 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37842@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+25869
http://master.php.net/manage/user-notes.php?action=delete+25869
http://master.php.net/manage/user-notes.php?action=reject+25869