|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-08-25 12:30 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 05:00:01 2025 UTC |
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