Created
February 28, 2015 09:57
-
-
Save yerbol89/fa059951b6d46d67efbc to your computer and use it in GitHub Desktop.
Kazakh and russian url convert
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 translitURL($str) | |
{ | |
$tr = 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","Ъ"=>"j","Ы"=>"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","ъ"=>"j", | |
"ы"=>"y","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya", | |
" "=> "-", "."=> "", "І"=> "i", | |
"і"=> "i", "Ң"=> "n", "ң"=> "n", | |
"Ү"=> "u", "ү"=> "u", "Қ"=> "q", | |
"қ"=> "q", "Ұ"=> "u", | |
"ұ"=> "u", "Ғ"=> "g", "ғ"=> "g", | |
"Ө"=> "o", "ө"=> "o", "Ә"=> "a", | |
"ә"=> "a" | |
); | |
// Убираю тире, дефисы внутри строки | |
$urlstr = str_replace('–'," ",$str); | |
$urlstr = str_replace('-'," ",$urlstr); | |
$urlstr = str_replace('—'," ",$urlstr); | |
// Убираю лишние пробелы внутри строки | |
$urlstr=preg_replace('/\s+/',' ',$urlstr); | |
if (preg_match('/[^A-Za-z0-9_\-]/', $urlstr)) { | |
$urlstr = strtr($urlstr,$tr); | |
$urlstr = preg_replace('/[^A-Za-z0-9_\-]/', '', $urlstr); | |
$urlstr = strtolower($urlstr); | |
return $urlstr; | |
} else { | |
return strtolower($str); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment