#40863 [Opn->Csd]: str_ireplace not behaving as expected
| From: | vrana@php.net | Date: | Fri, 23 Mar 2007 13:48:53 +0000 |
| Subject: | #40863 [Opn->Csd]: str_ireplace not behaving as expected | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969375822@lists.php.net to get a copy of this message | ||
ID: 40863
Updated by: vrana@php.net
Reported By: jonathan at sadowski dot us
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: Ubuntu
PHP Version: 5.2.1
New Comment:
"Every replacement with search array is performed on the result of
previous replacement."
Previous Comments:
------------------------------------------------------------------------
[2007-03-20 10:49:13] jonathan at sadowski dot us
Then at the very least it's a documentation problem, because that is
not clear in the documentation... to me, that's not desired
functionality.
------------------------------------------------------------------------
[2007-03-20 10:41:12] tony2001@php.net
Please read what I say:
str_ireplace() changes 'E' and 'e' to 'W' and then changes
'W' to 'G'.
------------------------------------------------------------------------
[2007-03-20 10:40:10] jonathan at sadowski dot us
Here's a more concrete example... The last line of the output should
be "WE THE PEOPLE OF THE UNITED STATES"
<?php
$phrase = "We the People of the United States";
$letters = explode(" ","A B C D E F G H I J K L M N O P Q R S T U V W X
Y Z");
$key = explode(" ","V T U O W Q E X Y K S D Z B M A I L J R C F G H P
N");
$TMP1 = str_ireplace($letters,$key,$phrase);
$TMP2 = str_ireplace($key,$letters,$TMP1);
echo $phrase . "\n";
echo $TMP1 . "\n";
echo $TMP2 . "\n";
?>
Actual output:
We the People of the United States
GG RHG AGMADG MI RHG CBPRGM JRFRGJ
WW TXW YWOYTW OQ TXW UZYTWO STVTWS
------------------------------------------------------------------------
[2007-03-20 10:28:41] jonathan at sadowski dot us
Perhaps you should read the expected result before marking it bogus,
and read through the sample code to see what its supposed to do.
The first word is "We", this cannot produce "GG" no matter what, as
"W"
and "e" are two different words.
------------------------------------------------------------------------
[2007-03-20 10:20:15] tony2001@php.net
..E .. W
..W .. G
E replaced with W
W replaced with G.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/40863
--
Edit this bug report at http://bugs.php.net/?id=40863&edit=1