AndrewP Posted November 11, 2010 Share Posted November 11, 2010 Hi, I'm pretty new to PHP, and I'm trying to write my own encoding/decoding script (not with base_64). I'd like to replace like all A's with B's, all B's with C's, C's with D's, and so on. How would I do this? Here's an example: String #1: "ABCDEFG" string #1 goes through my encryption string #2 (output): "BCDEFGH". How would I go about doing this? Thanks. Link to comment https://forums.phpfreaks.com/topic/218354-for-every-x-replace-it-with-y/ Share on other sites More sharing options...
simshaun Posted November 11, 2010 Share Posted November 11, 2010 Here ya go, but I must say this is probably rather pointless. $string = 'ABCDEFGZ'; $strlen = strlen($string); for ($x = 0; $x < $strlen; $x++) { $string[$x] = chr(ord($string[$x]) + (strtoupper($string[$x]) == 'Z' ? -25 : 1)); } echo $string; Link to comment https://forums.phpfreaks.com/topic/218354-for-every-x-replace-it-with-y/#findComment-1132902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.