Re: Amendment to String Problem

From: Date: Thu, 10 Apr 2003 03:33:34 +0000
Subject: Re: Amendment to String Problem
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-26975@lists.php.net to get a copy of this message
The problem is that it replaces letters already replaced. Use the strtr function, www.php.net/strtr. Chris Payne wrote:
Hi there Everyone, Here's a better example of the problem i'm having, there is probably a MUCH better way to do this, but here goes. I am using the following code: $passroutine = 'abcdefghijklmnopqrstuvwxyz'; $passroutine = str_replace("a", "z", $passroutine); $passroutine = str_replace("b", "y", $passroutine); $passroutine = str_replace("c", "x", $passroutine); $passroutine = str_replace("d", "w", $passroutine); $passroutine = str_replace("e", "v", $passroutine); $passroutine = str_replace("f", "u", $passroutine); $passroutine = str_replace("g", "t", $passroutine); $passroutine = str_replace("h", "s", $passroutine); $passroutine = str_replace("i", "r", $passroutine); $passroutine = str_replace("j", "q", $passroutine); $passroutine = str_replace("k", "p", $passroutine); $passroutine = str_replace("l", "o", $passroutine); $passroutine = str_replace("m", "n", $passroutine); $passroutine = str_replace("n", "m", $passroutine); $passroutine = str_replace("o", "l", $passroutine); $passroutine = str_replace("p", "k", $passroutine); $passroutine = str_replace("q", "j", $passroutine); $passroutine = str_replace("r", "i", $passroutine); $passroutine = str_replace("s", "h", $passroutine); $passroutine = str_replace("t", "g", $passroutine); $passroutine = str_replace("u", "f", $passroutine); $passroutine = str_replace("v", "e", $passroutine); $passroutine = str_replace("w", "d", $passroutine); $passroutine = str_replace("x", "c", $passroutine); $passroutine = str_replace("y", "b", $passroutine); $passroutine = str_replace("z", "a", $passroutine); which is SUPPOSED to replace letters, a because z and so on, but after it gets to m it screws up and displays: abcdefghijklmmlkjihgfedcba How can I do the above code in such a way that it won't produce this problem? Any help will be greatly appreciated :-) Regards Chris
-- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.

« previous php.db (#26975) next »