|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #68943 Error in documentation for preg_replace
Submitted: 2015-01-29 11:49 UTC Modified: 2015-02-15 00:32 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kalimatas at gmail dot com Assigned: danack (profile)
Status: Closed Package: PCRE related
PHP Version: Irrelevant OS:
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.
Block user comment
Status: Assign to:
Bug Type:
From: kalimatas at gmail dot com
New email:
PHP Version: OS:


 [2015-01-29 11:49 UTC] kalimatas at gmail dot com
From manual page:

In the example #2 for preg_replace there is a wrong output for the first case (before sorting arrays). It says the output will be:

The slow black bear jumped over the lazy dog.

But actually it should be:

The bear black slow jumped over the lazy dog.

Test script:
$string = 'The quick brown fox jumped over the lazy dog.';
$patterns = array();
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements = array();
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';
echo preg_replace($patterns, $replacements, $string);

Output according to docs: The slow black bear jumped over the lazy dog.
Actual output: The bear black slow jumped over the lazy dog.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-29 19:37 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: danack
 [2015-01-29 19:37 UTC]
Thanks, I've fixed it. It should show up as the correct version after the next manual build.

I've left it open and assigned to me so I remember to check that it's okay after the build.
 [2015-02-15 00:32 UTC]
-Status: Assigned +Status: Closed
 [2015-02-15 00:32 UTC]
Just checked, and it's done.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Aug 06 02:01:24 2020 UTC