php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kalimatas at gmail dot com
New email:
PHP Version: OS:

 

 [2015-01-29 11:49 UTC] kalimatas at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.preg-replace
---

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:
---------------
<?php
$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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-29 19:37 UTC] danack@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: danack
 [2015-01-29 19:37 UTC] danack@php.net
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] danack@php.net
-Status: Assigned +Status: Closed
 [2015-02-15 00:32 UTC] danack@php.net
Just checked, and it's done.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 18:01:35 2025 UTC