Created
February 3, 2018 00:34
-
-
Save spacebit-official/61152b202ec97ae708dbf2b7a3f4c28d to your computer and use it in GitHub Desktop.
translit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function translit($str, $val = 'en') { | |
$translit = array( | |
'а' => 'a', 'б' => 'b', 'в' => 'v', | |
'г' => 'g', 'д' => 'd', 'е' => 'e', | |
'ё' => 'yo', 'ж' => 'zh', 'з' => 'z', | |
'и' => 'i', 'й' => 'j', 'к' => 'k', | |
'л' => 'l', 'м' => 'm', 'н' => 'n', | |
'о' => 'o', 'п' => 'p', 'р' => 'r', | |
'с' => 's', 'т' => 't', 'у' => 'u', | |
'ф' => 'f', 'х' => 'x', 'ц' => 'c', | |
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'shh', | |
'ь' => '\'', 'ы' => 'y', 'ъ' => '\'\'', | |
'э' => 'e\'', 'ю' => 'yu', 'я' => 'ya', | |
'А' => 'A', 'Б' => 'B', 'В' => 'V', | |
'Г' => 'G', 'Д' => 'D', 'Е' => 'E', | |
'Ё' => 'YO', 'Ж' => 'Zh', 'З' => 'Z', | |
'И' => 'I', 'Й' => 'J', 'К' => 'K', | |
'Л' => 'L', 'М' => 'M', 'Н' => 'N', | |
'О' => 'O', 'П' => 'P', 'Р' => 'R', | |
'С' => 'S', 'Т' => 'T', 'У' => 'U', | |
'Ф' => 'F', 'Х' => 'X', 'Ц' => 'C', | |
'Ч' => 'CH', 'Ш' => 'SH', 'Щ' => 'SHH', | |
'Ь' => '\'', 'Ы' => 'Y\'', 'Ъ' => '\'\'', | |
'Э' => 'E\'', 'Ю' => 'YU', 'Я' => 'YA', | |
); | |
if($val == 'en') { | |
return $word = strtr($str, $translit); // транслитерация. Переменная $word получит значение 'prochee' | |
} | |
elseif ($val == 'ru') { | |
return $word = strtr($str, array_flip($translit)); // обратная транслитерация. Переменная $word получит значение 'прочее' | |
} | |
} | |
echo translit('kak dela', 'ru'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment