Вроде работает, но я не настоящий ПХПец.
# е, ю, я, ё
$yotifiable = [0xB5, 0x8E, 0x8F, 0x91];
# а,е,и,о,у,ъ,ы,ь,э,ю,я,ё
$yotifiers = [0xB0, 0xB5, 0xB8, 0xBe, 0x83, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x91];
# а = 0x0D0B0, р = 0xD180, ё = 0xD191
# а, ..., э, ю, я, ѐ, ё.
$codes = ["a", "b", "v", "g", "d", "e", "zh", "z", "i", "y", "k",
"l", "m", "n", "o", "p", "r", "s", "t", "u", "f", "h", "ts",
"ch", "sh", "sch", "'", "y", "'", "e", "u", "a", "e", "o"];
$is_yotified = true;
$shift = 0;
$result = "";
foreach(str_split("ятолькокириллица") as $char){
$char = ord($char);
if($shift != 0){
if($is_yotified && in_array($char, $yotifiable))
$result .= "y";
$result .= $codes[$char - $shift]; # bounds checked?
$is_yotified = in_array($char, $yotifiers);
$shift = 0;
}
else if($char == 0xD0) # а-п
$shift = 0xB0;
else if($char == 0xD1) # р-ё
$shift = 0x80 - 16;
}
echo $result;