php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78168 Reference Format is \n instead of \\n
Submitted: 2019-06-14 20:44 UTC Modified: 2019-06-15 02:17 UTC
From: michael dot nique at gmx dot de Assigned:
Status: Verified Package: PCRE related
PHP Version: Irrelevant OS: Linux
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: michael dot nique at gmx dot de
New email:
PHP Version: OS:

 

 [2019-06-14 20:44 UTC] michael dot nique at gmx dot de
Description:
------------
---
From manual page: https://php.net/function.preg-replace
---

The documentation states: "replacement may contain references of the form \\n or $n"

I think it should be "\n" instead of "\\n", see test-script 

Test script:
---------------
echo(preg_replace('/#.*#/', 'A\0B', '#test#'));


Expected result:
----------------
A\0B

Actual result:
--------------
A#test#B

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-15 02:17 UTC] requinix@php.net
-Status: Open +Status: Verified -Package: Regexps related +Package: PCRE related
 [2019-06-15 02:17 UTC] requinix@php.net
\\n is because people are liable to use double-quoted strings so the backslash would have to be escaped. Doubled backslashes will work for both types of strings without needing a second thought. But IMO the section there is a bit overzealous on the "you need doubled backslashes" when the truth is that PCRE only wants one, so maybe it could be adjusted a bit.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Jan 29 07:01:23 2020 UTC