- chr: documentation ( source)
- str_split: documentation ( source)
- ord: documentation ( source)
<?php
$string = "hello my friend";
$newString = '';
foreach(str_split($string) as $char) {
$asciiCode = ord($char);
// 97 - a
// 122 - z
if ($asciiCode >= 97 && $asciiCode < 122) {
$char += 1;
}
if (in_array($char, ['a', 'e', 'y', 'u', 'i', 'o'])) {
// not 32, because we already added 1 before
$char -= 33;
}
$newString .= chr($char);
}
echo $newString;