Skip to content

Instantly share code, notes, and snippets.

@ildarkhasanshin
Forked from danillab/translit.php
Created January 19, 2020 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ildarkhasanshin/4b2ce59d8af0bf84a33c5249132f9f1a to your computer and use it in GitHub Desktop.
Save ildarkhasanshin/4b2ce59d8af0bf84a33c5249132f9f1a to your computer and use it in GitHub Desktop.
Транслит для Яндекса
<?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