php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25234 str_replace misfunction?
Submitted: 2003-08-25 06:27 UTC Modified: 2003-08-25 12:30 UTC
From: info at sima-pc dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.1 OS: WIN98
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: info at sima-pc dot com
New email:
PHP Version: OS:

 

 [2003-08-25 06:27 UTC] info at sima-pc dot com
Description:
------------
It's not exactly a bug but I believe str_replace has a problem that can be solved.

In the first sample below, after replacing "ONE" with "TWO WORDS", process follows with next array item and it changes "TWO" with "MANY LETTERS".

After the first successful replacement, shouldn't it stop replacing? IMHO it will be the right function flow.

Thanks,

         David Gimeno i Ayuso

Reproduce code:
---------------
<?php

$match=array("ONE","TWO","THREE");
$replace=array("TWO WORDS","MANY LETTERS","OTHER IDEAS");
$sample="ONE SAMPLE";
echo "first=",str_replace($match,$replace,$sample);

$match=array("TWO","ONE","THREE");
$replace=array("MANY LETTERS","TWO WORDS","OTHER IDEAS");
$sample="ONE SAMPLE";
echo "second=",str_replace($match,$replace,$sample);

?>


Expected result:
----------------
first=TWO WORDS SAMPLE
second=TWO WORDS SAMPLE

Actual result:
--------------
first=MANY LETTERS WORDS SAMPLE
second=TWO WORDS SAMPLE

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-25 12:30 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is expected behaviour.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 12:01:32 2024 UTC