Is there a php function to convert text like "пример !? я ссылка *&" to seo url "primer-ya-ssilka"

    1 answer 1

    This is a specific need for Russia - so this is not built in. It will help self-made translit like:

     class seoTranslit { static public $rustolat = array( 'жё' => 'zho', // жёлоб -> zholob 'жю' => 'zhu', // жюри -> zhuri 'чё' => 'cho', // чёлка -> cholka 'щё' => 'shcho', // щётка -> shchotka 'щ' => 'shch', 'шю' => 'shu', // парашют -> parashut 'ч' => 'ch', 'ц' => 'ts', 'х' => 'kh', 'ю' => 'yu', 'я' => 'ya', 'ё' => 'yo', 'ж' => 'zh', 'ш' => 'sh', 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'ъ' => '', 'ы' => 'y', 'ьо' => 'io', // бульон -> bulion 'ь' => '', 'э' => 'e', 'шё' => 'sho', // шёлк -> sholk ); static public function go($string) { $obfuscated = trim( mb_strtolower(preg_replace('/\s+/u', '-', preg_replace('/\W+/u', ' ', $string) )), '-'); $rustolat_re = '/'. implode("|", array_keys(self::$rustolat)) .'/'; return preg_replace_callback($rustolat_re, function($m){ return self::$rustolat[$m[0]];}, $obfuscated); } } 

    UPD :
    Corrected the code. The class working at the established coding utf-8 is

     setlocale(LC_ALL,'ru_RU.utf8'/*может отличаться на разных серверах*/); mb_internal_encoding("UTF-8"); mb_regex_encoding('UTF-8'); 
    • Class for one function? :) - Visman
    • @Visman not really. I just copied from my sorts. There is also a fp of reverse translit in it - but since it does not concern the question, it is cut out) - Goncharov Alexander