-
-
Save ildarkhasanshin/fd6aca64ba82843716921cbcdb6dfdc4 to your computer and use it in GitHub Desktop.
Translit php
This file contains hidden or 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
function translit_str( $str, $maxLength = 100, $encode = 'utf-8' ) { | |
$tr = array( | |
"А" => "a", | |
"Б" => "b", | |
"В" => "v", | |
"Г" => "g", | |
"Д" => "d", | |
"Е" => "e", | |
"Ё" => "yo", | |
"Ж" => "zh", | |
"З" => "z", | |
"И" => "i", | |
"Й" => "y", | |
"К" => "k", | |
"Л" => "l", | |
"М" => "m", | |
"Н" => "n", | |
"О" => "o", | |
"П" => "p", | |
"Р" => "r", | |
"С" => "s", | |
"Т" => "t", | |
"У" => "u", | |
"Ф" => "f", | |
"Х" => "h", | |
"Ц" => "c", | |
"Ч" => "ch", | |
"Ш" => "sh", | |
"Щ" => "shch", | |
"Ъ" => "", | |
"Ы" => "y", | |
"Ь" => "", | |
"Э" => "e", | |
"Ю" => "yu", | |
"Я" => "ya", | |
"а" => "a", | |
"б" => "b", | |
"в" => "v", | |
"г" => "g", | |
"д" => "d", | |
"е" => "e", | |
"ё" => "yo", | |
"ж" => "zh", | |
"з" => "z", | |
"и" => "i", | |
"й" => "y", | |
"к" => "k", | |
"л" => "l", | |
"м" => "m", | |
"н" => "n", | |
"о" => "o", | |
"п" => "p", | |
"р" => "r", | |
"с" => "s", | |
"т" => "t", | |
"у" => "u", | |
"ф" => "f", | |
"х" => "h", | |
"ц" => "c", | |
"ч" => "ch", | |
"ш" => "sh", | |
"щ" => "shch", | |
"ъ" => "", | |
"ы" => "y", | |
"ь" => "", | |
"э" => "e", | |
"ю" => "yu", | |
"я" => "ya", | |
" " => "-", | |
"." => "", | |
"," => "", | |
"/" => "", | |
"\"" => "", | |
"'" => "", | |
"/" => "", | |
":" => "", | |
"(" => "", | |
")" => "", | |
"!" => "", | |
"&" => "", | |
""" => "", | |
"«" => "", | |
"»" => "", | |
"%" => "", | |
"-" => "-", | |
"&" => "", | |
"$" => "", | |
"«" => "", | |
"»" => "", | |
"+" => "", | |
";" => "", | |
"’" => "", | |
); | |
$res = trim( strtr( $str, $tr ), "-" ); | |
$tr2 = array( | |
'---' => '-', | |
); | |
$res = strtr( $res, $tr2 ); | |
$res = mb_strtolower( $res, $encode ); | |
$res = mb_substr( $res, 0, $maxLength, $encode ); | |
return $res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment