Bug #12477 Updated: preg_replace evaluates dollar signs as variables (eg $1,000 becomes ,000)
| From: | Grant dot Walters at walters dot co dot nz | Date: | Mon, 06 Aug 2001 22:53:54 +0000 |
| Subject: | Bug #12477 Updated: preg_replace evaluates dollar signs as variables (eg $1,000 becomes ,000) | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-62364@lists.php.net to get a copy of this message | ||
ID: 12477
User updated by: Grant.Walters@walters.co.nz
Reported By: Grant.Walters@walters.co.nz
Status: Closed
Bug Type: Feature/Change Request
Operating System: Linux and SCO
PHP Version: 4.0.6
New Comment:
I was trying to have to walk the array twice.
The following works:
$pagevars = str_replace("$","\\\$",$pagevars);
$page = preg_replace($template,$pagevars,$page);
The reason for using preg_replace is that it does a recursive? replace.
My pagevars array actually has about 40 variables and the intention is to allow website designers to
define their own additional variables that are added to the template string.
Thanks for your help.
Previous Comments:
------------------------------------------------------------------------
[2001-08-06 17:29:56] andrei@php.net
To QA people (Andy): please don't be hasty.
------------------------------------------------------------------------
[2001-08-06 17:26:23] andy@php.net
reopened and reclassified as a feature request.
------------------------------------------------------------------------
[2001-08-06 17:26:15] andrei@php.net
If you don't want to use \n or $n substitution, then maybe you are better off using
str_replace()?
------------------------------------------------------------------------
[2001-08-06 17:24:10] Grant.Walters@walters.co.nz
Is it possible to ask that the this be included as a new feature?
A switch to tell the PCRE engine? to ignore variable substitution?
It would make things a lot easier, I think.
Thanks
------------------------------------------------------------------------
[2001-08-06 12:49:00] andrei@php.net
That's right, you need to escape $ in your replacement strings.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/?id=12477
Edit this bug report at http://bugs.php.net/?id=12477&edit=1