From:             info at sima-pc dot com
Operating system: WIN98
PHP version:      4.3.1
PHP Bug Type:     Strings related
Bug description:  str_replace misfunction?

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

-- 
Edit bug report at http://bugs.php.net/?id=25234&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25234&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25234&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25234&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25234&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25234&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25234&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25234&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25234&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25234&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25234&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25234&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25234&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25234&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25234&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25234&r=gnused

Reply via email to