php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #72341 Inconsitent $ escaping in preg_replace replacement patterns.
Submitted: 2016-06-06 08:54 UTC Modified: 2016-06-06 16:55 UTC
From: mark at barrenfrozenwasteland dot com Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: N/A
Private report: No CVE-ID: None
 [2016-06-06 08:54 UTC] mark at barrenfrozenwasteland dot com
Description:
------------
---
From manual page: http://www.php.net/function.preg-replace
---
"When working with a replacement pattern where a backreference is immediately followed by another number (i.e.: placing a literal number immediately after a matched pattern), you cannot use the familiar \\1 notation for your backreference. \\11, for example, would confuse preg_replace() since it does not know whether you want the \\1 backreference followed by a literal 1, or the \\11 backreference followed by nothing. In this case the solution is to use \${1}1. This creates an isolated $1 backreference, leaving the 1 as a literal."

The second-last sentence is confusing since this appears to contradict 2 other parts of the page: the paragraph above which says "replacement may contain references of the form \\n or (since PHP 4.0.4) $n" (no \$), and Example #1 which uses single-quoted string so doesn't require \$.

It would be less confusing if all parts of the page used the same style when describing $-delimited backreferences. #47797 also suggested drawing more attention to the escaping requirements, which could be helpful.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-06 16:54 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=339301
Log: fix #72341: Inconsitent $ escaping in preg_replace replacement patterns
 [2016-06-06 16:55 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2016-06-06 16:55 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:07 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=91b8b05f52dcf548bb3c1a1fc4404dbfb7b2a800
Log: fix #72341: Inconsitent $ escaping in preg_replace replacement patterns
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 03:01:29 2024 UTC