Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cyrillic transliteration in PHP

How to transliterate cyrillic characters into latin letters?

E.g. Главная страница -> Glavnaja stranica 

This Transliteration PHP Extension would do this very well, but I can't install it on my server.

It would be best to have the same implementation but in PHP.

like image 370
Sfisioza Avatar asked Sep 18 '11 12:09

Sfisioza


1 Answers

Try following code

$textcyr="Тествам с кирилица";         $textlat="I pone dotuk raboti!";         $cyr = ['Љ', 'Њ', 'Џ', 'џ', 'ш', 'ђ', 'ч', 'ћ', 'ж', 'љ', 'њ', 'Ш', 'Ђ', 'Ч', 'Ћ', 'Ж','Ц','ц', 'а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п', 'р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я', 'А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П', 'Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я'         ];         $lat = ['Lj', 'Nj', 'Dž', 'dž', 'š', 'đ', 'č', 'ć', 'ž', 'lj', 'nj', 'Š', 'Đ', 'Č', 'Ć', 'Ž','C','c', 'a','b','v','g','d','e','io','zh','z','i','y','k','l','m','n','o','p', 'r','s','t','u','f','h','ts','ch','sh','sht','a','i','y','e','yu','ya', 'A','B','V','G','D','E','Io','Zh','Z','I','Y','K','L','M','N','O','P', 'R','S','T','U','F','H','Ts','Ch','Sh','Sht','A','I','Y','e','Yu','Ya'         ];         $textcyr = str_replace($cyr, $lat, $textcyr);         $textlat = str_replace($lat, $cyr, $textlat);         echo("$textcyr $textlat"); 
like image 182
Tural Ali Avatar answered Oct 06 '22 04:10

Tural Ali