Is there such a function or method in PHP to translate Russian letters into English?
- 3Functions for sure there is no. And there are plenty of ways to transliterate. As well as ready-made codes ... only the standards of transliteration have never been one, and, accordingly, the results they give are somewhat unequal - remember this. - Akina
- ru.stackoverflow.com/q/158104/186083 ru.stackoverflow.com/q/658067/186083 - Visman
|
1 answer
No built-in function. But you can use a bunch of them on the Internet. for example
function translit($s) { $s = (string) $s; // преобразуем в строковое значение $s = trim($s); // убираем пробелы в начале и конце строки $s = function_exists('mb_strtolower') ? mb_strtolower($s) : strtolower($s); // переводим строку в нижний регистр (иногда надо задать локаль) $s = strtr($s, array('а'=>'a','б'=>'b','в'=>'v','г'=>'g','д'=>'d','е'=>'e','ё'=>'e','ж'=>'j','з'=>'z','и'=>'i','й'=>'y','к'=>'k','л'=>'l','м'=>'m','н'=>'n','о'=>'o','п'=>'p','р'=>'r','с'=>'s','т'=>'t','у'=>'u','ф'=>'f','х'=>'h','ц'=>'c','ч'=>'ch','ш'=>'sh','щ'=>'shch','ы'=>'y','э'=>'e','ю'=>'yu','я'=>'ya','ъ'=>'','ь'=>'')); return $s; // возвращаем результат } echo translit("Получилось!"); |