С множеством (надеюсь) полезных комментариев, объясняющих, что делает каждая строка
// Set up a "transposition" table of letters,
// showing what each letter should become
$letterLookup = array(
'a' => 'd', 'b' => 'a', 'c' => 'h', 'd' => 'b',
'e' => 'c', 'f' => 'e', 'g' => 'f', 'h' => 'g',
'i' => 'p', 'j' => 'j', 'k' => 'k', 'l' => 'm',
'm' => 'q', 'n' => 'r', 'o' => 'i', 'p' => 'o',
'q' => 's', 'r' => 'l', 's' => 't', 't' => 'n',
'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x',
'y' => 'y', 'z' => 'z'
);
// This is the initial input string
$inputString = 'a.p.r.i.c.o.t';
// Display our initial input string (just for test purposes)
echo $inputString,'<hr />';
// Convert the input string into an array, so we can loop through each
// letter more easily, splitting on the dots
$stringArray = explode('.',$inputString);
// Initialise the new array that we're going to create in out new
// language/code
$newStringArray = array();
// Loop through each letter from the input string one after the other
// (easy with an array)
foreach($stringArray as $letter) {
// If the letter is in our transposition table...
if (isset($letterLookup[$letter])) {
// then add that new letter to our new
// language/code array
$newStringArray[] = $letterLookup[$letter];
} else {
// Otherwise (if it's a punctuation mark, for example)
// add that to our new language/code array
// without changing it
$newStringArray[] = $letter;
}
}
// Change our translated/encoded array back into a string,
// putting the dots back in
$newString = implode('.',$newStringArray);
// Then display our new string
echo $newString;