1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- namespace app\helpers;
- class Transliterator
- {
- public static function convert(string $string):string
- {
- $converter = array(
- 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
- 'е' => 'e', 'ё' => 'e', 'ж' => 'zh', 'з' => 'z', 'и' => 'i',
- 'й' => 'y', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n',
- 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't',
- 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch',
- 'ш' => 'sh', 'щ' => 'sch', 'ь' => '', 'ы' => 'y', 'ъ' => '',
- 'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
- 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D',
- 'Е' => 'E', 'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z', 'И' => 'I',
- 'Й' => 'Y', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N',
- 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T',
- 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'Ch',
- 'Ш' => 'Sh', 'Щ' => 'Sch', 'Ь' => '', 'Ы' => 'Y', 'Ъ' => '',
- 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya',
- );
- $value = strtr($string, $converter);
- return $value;
- }
- public static function toUrl(string $string):string
- {
- $translit = self::convert($string);
- return strtolower(preg_replace("/([^a-zA-Z0-9-])/","",trim(str_replace(" ",'-',$translit))));
- }
- }
|