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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.