|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-03-20 10:10 UTC] jonathan at sadowski dot us
Description:
------------
str_ireplace doesn't behave as expected when $search and $replace are equally sized arrays, and $subject is a string containing mixed case.
Reproduce code:
---------------
<?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 = $letters;
shuffle($key);
echo sizeof($letters) . "\n" . sizeof($key) . "\n\n";
echo implode(" ",$letters) . "\n" . implode(" ",$key) . "\n" . str_ireplace($letters,$key,$phrase);
?>
Expected result:
----------------
26
26
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
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
GW RXW AWMADW MQ RXW CBYRWO JRVRWJ
Actual result:
--------------
26
26
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
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
GG RHG AGMADG MI RHG CBPRGM JRFRGJ
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 13:00:01 2025 UTC |
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