Cagri Posted July 8, 2009 Share Posted July 8, 2009 Hello, Could you explain to me, why this code doesn't work correctly? Thanks. <?php $text = "abcdefghijklmnopqrstuvwxyz"; $search = array("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"); $replace = array("z","y","x","w","v","u","t","s","r","q","p","o","n","m","l","k","j","i","h","g","f", "e","d","c","b","a"); $text = str_replace($search,$replace,$text); echo "Encoded: " . $text; echo "<br>"; $text = str_replace($replace,$search,$text); echo "Decoded: " . $text; ?> Returns: Encoded: abcdefghijklmmlkjihgfedcba Decoded: zyxwvutsrqponnopqrstuvwxyz Link to comment https://forums.phpfreaks.com/topic/165166-str_replace-problem/ Share on other sites More sharing options...
sasa Posted July 8, 2009 Share Posted July 8, 2009 your code works this 1st replace all 'a' to 'z', then 'b' etc. code in last iteration replace back 'z' to 'a' Link to comment https://forums.phpfreaks.com/topic/165166-str_replace-problem/#findComment-870892 Share on other sites More sharing options...
Cagri Posted July 8, 2009 Author Share Posted July 8, 2009 Nope it doesn't work correctly Encoded: abcdefghijklmmlkjihgfedcba Decoded: zyxwvutsrqponnopqrstuvwxyz it works correct until "m" word! but there are two "mm" and after it is continue incorrect... Link to comment https://forums.phpfreaks.com/topic/165166-str_replace-problem/#findComment-870895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.