How do you change 'hElLo WoRlD' to 'HeLlO wOrLd' in PHP?

Answer:
The process will work similar to a cryptoquip. First, you need to set up a conversion array. Then, run a strtr() and make the conversion into a new string. The code will look something like this:
$input = "hElLo WoRlD";
$convert = array('A' => 'a', 'B' => 'b' ... ... 'Z' => 'z', 'a' => 'A' ... ... 'y' => 'Y', 'z' => 'Z');
$output = strtr($input, $convert);

You can also look into generating the array by other means, such as looking through char codes. It is important to make sure that the array keys are the start letters and the array values are the end letters. It does not matter in what order you populate the array, as long as all letter pairs (upper-to-lower and the other way too) are present.
Contributor: Bryan
First answer by Bryan Shepard. Last edit by Bryan Shepard. Contributor trust: 114 [recommend contributor recommended]. Question popularity: 4 [recommend question].