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
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:
MUST BE VALID
Solve the problem:
42 - 23 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 07:01:28 2024 UTC