Jump to content

str_replace problem!


Cagri

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.