Doc #72341 [Opn->Csd]: Inconsitent $ escaping in preg_replace replacement patterns.
| From: | cmb@php.net | Date: | Mon, 06 Jun 2016 16:55:51 +0000 |
| Subject: | Doc #72341 [Opn->Csd]: Inconsitent $ escaping in preg_replace replacement patterns. | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13488@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72341&edit=1
ID: 72341
Updated by: cmb@php.net
Reported by: mark at barrenfrozenwasteland dot com
Summary: Inconsitent $ escaping in preg_replace replacement
patterns.
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: N/A
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2016-06-06 16:54:47] 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 08:54:22] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72341&edit=1