|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
3 + 34 = ?
Subscribe to this entry?

 [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-2021 The PHP Group
All rights reserved.
Last updated: Tue Oct 19 10:03:36 2021 UTC