Created
May 11, 2012 09:05
-
-
Save dimak57/2658533 to your computer and use it in GitHub Desktop.
translit function (Транслит)
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
public function translit($string) { | |
$zamena = array( | |
"А" => "A", "а" => "a", "," => "", | |
"Б" => "B", "б" => "b", "(" => "", | |
"В" => "V", "в" => "v", ")" => "", | |
"Г" => "G", "г" => "g", "#" => "", | |
"Д" => "D", "д" => "d", "@" => "", | |
"Е" => "E", "е" => "e", "%" => "", | |
"Ё" => "YO", "ё" => "yo", "&" => "", | |
"Ж" => "J", "ж" => "j", "$" => "", | |
"З" => "Z", "з" => "z", "^" => "", | |
"И" => "I", "и" => "i", "!" => "", | |
"Й" => "Y", "й" => "y", "?" => "", | |
"К" => "K", "к" => "k", "<" => "", | |
"Л" => "L", "л" => "l", ">" => "", | |
"М" => "M", "м" => "m", ";" => "", | |
"Н" => "N", "н" => "n", ":" => "", | |
"О" => "O", "о" => "o", "'" => "", | |
"П" => "P", "п" => "p", '"' => "", | |
"Р" => "R", "р" => "r", " " => "-", | |
"С" => "S", "с" => "s", "." => ".", | |
"Т" => "T", "т" => "t", "+" => "", | |
"У" => "U", "у" => "u", "/" => "", | |
"Ф" => "F", "ф" => "f", "\\" => "", | |
"Х" => "H", "х" => "h", "-" => "-", | |
"Ц" => "TS", "ц" => "ts", "_" => "_", | |
"Ч" => "CH", "ч" => "ch", | |
"Ш" => "SH", "ш" => "sh", | |
"Щ" => "SCH", "щ" => "sch", | |
"Ъ" => "", "ъ" => "y", | |
"Ы" => "YI", "ы" => "yi", | |
"Ь" => "", "ь" => "", | |
"Э" => "E", "э" => "e", | |
"Ю" => "YU", "ю" => "yu", | |
"Я" => "YA", "я" => "ya"); | |
$translit = preg_replace('#-{1,}#', '-', strtr($string, $zamena)); | |
$translit = preg_replace('#_{1,}#', '_', $translit); | |
$translit = preg_replace('/\s{1,}/sm','',$translit); | |
$translit = preg_replace("#[^a-zA-Z\.0-9-_]#i", "", $translit); | |
$translit = strtolower($translit); | |
return trim($translit); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment