-
-
Save ildarkhasanshin/4b2ce59d8af0bf84a33c5249132f9f1a to your computer and use it in GitHub Desktop.
Транслит для Яндекса
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
<?php | |
function translit($str) { | |
$tr = 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","щ"=>"shh","ъ"=>"","ы"=>"y","ь"=>"","э"=>"e","ю"=>"u","я"=>"ya","—"=>"-","«"=>"","»"=>"","…"=>""," "=>"-","№"=>"#"); | |
$str = mb_strtolower($str,'utf-8'); | |
// $str = preg_replace("/\s+/",' ',$str); | |
$str = strtr(trim($str), $tr); | |
$str = trim(preg_replace("/\-+/",'-',$str),'- '); | |
$str = preg_replace('~[^a-z0-9/-]~', '', $str); | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment