php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10626 escaping doesn't work in the replacement clause
Submitted: 2001-05-03 03:04 UTC Modified: 2001-05-04 07:15 UTC
From: hover at mi dot ru Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.0.5 OS: FreeBSD 4.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hover at mi dot ru
New email:
PHP Version: OS:

 

 [2001-05-03 03:04 UTC] hover at mi dot ru
The problem is that preg_replace() ignores escaping of $nn sequence in the replacement string.
<?
$str = preg_replace("/a/", "\$1000", "test ... a ... test");
echo $str;
?>

test ... 00 ... test 

-----------
#!/usr/local/bin/perl -w

$_ = "test ... a ... test";
s/a/\$1000/;
print;
-----------
test ... $1000 ... test

This feature leads to impossibility of passing strings like '$1000' via phplib template variables.

PHP 4.0.4pl1, 4.0.5

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-03 08:04 UTC] cynic@php.net
You escaped the $1000 on the PHP level, so literal $1000 was sent to PCRE, where $10 was interpreted as a backreference, and since there aren't 10 capturing subpatterns in the pattern, you get an empty string for $10, and the rest is taken as a literal string.

Send further questions to php-general@ (after you RTFM, of course).
 [2001-05-04 07:15 UTC] hover at mi dot ru
Thanks for educating me and sorry for waisting your time.
Though, phplib template.inc needs to be changed to work with such variables.

Something like this:

$tempvars = preg_replace("/\\$/", "\\\\\$", $this->varvals);

But it's a phplib's, not PHP thing. Thanks.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Nov 27 23:03:15 2021 UTC