self::CYRILLIC, 'latin' => self::LATIN ]; array_walk($exceptions["cyrillic"], function (&$currentword) { $currentword = preg_replace("/^/", "/", $currentword); $currentword = preg_replace("/$/", "/iu", $currentword); }); $text = preg_replace_callback($exceptions["cyrillic"], function ($matches) use ($exceptions) { $check = mb_substr($matches[0], 0, 1); if (mb_strtoupper($check) == $check) { $replacement = preg_replace($exceptions["cyrillic"], $exceptions["latin"], $matches[0]); return ucfirst($replacement); } else { $replacement = preg_replace($exceptions["cyrillic"], $exceptions["latin"], $matches[0]); return $replacement; } }, $text); //Замены букв $text = str_replace('къ', 'q', $text); // къ $text = str_replace('КЪ', 'Q', $text); // КЪ $text = str_replace('Къ', 'Q', $text); // Къ $text = str_replace('гь', 'h', $text); // гь $text = str_replace('ГЬ', 'H', $text); // ГЬ $text = str_replace('Гь', 'H', $text); // Гь $text = str_replace('гъ', 'ğ', $text); // гъ $text = str_replace('ГЪ', 'Ğ', $text); // ГЪ $text = str_replace('Гъ', 'Ğ', $text); // Гъ $text = str_replace('уь', 'ü', $text); // уь $text = str_replace('УЬ', 'Ü', $text); // УЬ $text = str_replace('Уь', 'Ü', $text); // Уь $text = str_replace('оь', 'ö', $text); // оь $text = str_replace('ОЬ', 'Ö', $text); // ОЬ $text = str_replace('Оь', 'Ö', $text); // Оь $text = preg_replace('/\bЕ(?=\p{Lu})/u', 'YE', $text); // ^Е+заглавные $text = preg_replace('/\bЕ(?=\p{Ll})/u', 'Ye', $text); // ^Е+прописные $text = preg_replace('/\bе/u', 'ye', $text); // е+прописные $text = preg_replace('/(?<=[аоуэыяёюеиьъАОУЭЫЯЁЮЕИЬЪ])е/u', 'ye', $text); // гласная(любой регистр)+е $text = preg_replace('/(?<=[аоуэыяёюеиьъАОУЭЫЯЁЮЕИЬЪ])Е/u', 'YE', $text); // гласная(любой регистр)+Е $text = preg_replace('/(?<=[бвгджзклмнпрстфхцчшщйБВГДЖЗКЛМНПРСТФХЦЧШЩЙ])Я/u', 'Ä', $text); // согласная(любой регистр)+Я $text = preg_replace('/(?<=[бвгджзклмнпрстфхцчшщйБВГДЖЗКЛМНПРСТФХЦЧШЩЙ])я/u', 'ä', $text); // согласная(любой регистр)+я $text = preg_replace('/Я(?=\p{Ll})/u', 'Ya', $text); // Я + прописные $text = preg_replace('/\bЯ\b/u', 'Ya', $text); // Я отдельно стоящаяe $text = preg_replace('/(\bЁ|(?:(?<=Э)|(?<=E)|(?<=УЬ)|(?<=ОЬ)|(?<=Ю)|(?<=Ё|(?<=Ъ)))Ё)(?=([БВГДЖЗКЛМНПРСТФХЦЧШЩЙЬЪЁЮ]*(Е|И|УЬ|ОЬ|YE|Ye|\b))|К\b|\b)/u', 'YÖ', $text); $text = preg_replace('/(\bЁ|(?:(?<=э)|(?<=e)|(?<=уь)|(?<=оь)|(?<=ю)|(?<=Э)|(?<=E)|(?<=УЬ)|(?<=ОЬ)|(?<=Уь)|(?<=Оь)|(?<=ё)|(?<=Ё)|(?<=ъ)|(?<=Ъ))Ё)(?=([бвгджзклмнпрстфхцчшщйьъёю]*(Е|И|УЬ|ОЬ|е|и|уь|оь|YE|Ye|ye|\b))|К\b|к\b|\b)/u', 'Yö', $text); $text = preg_replace('/(\bЁ|(?<=[АОУЫЮЯЁЪ])Ё)(?=([БВГДЖЗКЛМНПРСТФХЦЧШЩЙЬЪĞQ]*(А|Ы|У|О|Ю|Ё|\b))|Q\b)/u', 'YO', $text); $text = preg_replace('/(\bЁ|(?<=[аоуыюяёъАОУЫЮЯЁЪ])Ё)(?=([бвгджзклмнпрстфхцчшщйьъğq]*(А|Ы|У|О|Ю|Ё|а|ы|у|о|ю|ё|\b))|Q\b|q\b)/u', 'Yo', $text); $text = preg_replace('/(\bЮ|(?:(?<=Э)|(?<=E)|(?<=УЬ)|(?<=ОЬ)|(?<=Ё)|(?<=Ö)|(?<=Ъ))Ю)(?=([БВГДЖЗКЛМНПРСТФХЦЧШЩЙЬЪЮЁÖ]*(Е|И|УЬ|ОЬ|YE|Ye|\b))|К\b)/u', 'YÜ', $text); $text = preg_replace('/(\bЮ|(?:(?<=э)|(?<=e)|(?<=уь)|(?<=оь)|(?<=ю)|(?<=Э)|(?<=E)|(?<=УЬ)|(?<=ОЬ)|(?<=Уь)|(?<=Оь)|(?<=ё)|(?<=Ё)|(?<=ö)|(?<=ъ)|(?<=Ъ))Ю)(?=([бвгджзклмнпрстфхцчшщйьъюёö]*(Е|И|УЬ|ОЬ|е|и|уь|оь|YE|Ye|ye|\b))|К\b|к\b)/u', 'Yü', $text); $text = preg_replace('/(\bЮ|(?<=[АОУЫЯЁЪO])Ю)(?=([БВГДЖЗКЛМНПРСТФХЦЧШЩЙЬЪĞQ]*(А|Ы|У|О|Ё|Ю|YO|\b))|КЪ\b)/u', 'YU', $text); $text = preg_replace('/(\bЮ|(?<=[аоуыяёъАОУЫЯЁЪOo])Ю)(?=([бвгджзклмнпрстфхцчшщйьъğq]*(А|Ы|У|О|Ё|Ю|YO|Yo|а|ы|у|о|ё|ю|yo|\b))|КЪ\b|къ\b)/u', 'Yu', $text); $text = preg_replace('/(\bё|(?:(?<=э)|(?<=e)|(?<=ü)|(?<=ö)|(?<=ю)|(?<=Э)|(?<=E)|(?<=Ü)|(?<=Ö)|(?<=ё)|(?<=Ё)|(?<=ъ)|(?<=Ъ))ё)(?=([бвгджзклмнпрстфхцчшщйьъёю]*(Е|И|Ü|ОЬ|е|и|ü|ö|YE|Ye|ye|\b))|К\b|к\b|\b)/u', 'yö', $text); $text = preg_replace('/(\bё|(?<=[аоуыюяёъАОУЫЮЯЁЪ])ё)(?=([бвгджзклмнпрстфхцчшщйьъğq]*(А|Ы|У|О|Ю|Ё|а|ы|у|о|ю|ё|\b))|Q\b|q\b)/u', 'yo', $text); $text = preg_replace('/(\bю|(?:(?<=э)|(?<=e)|(?<=ü)|(?<=ö)|(?<=ю)|(?<=Э)|(?<=E)|(?<=Ü)|(?<=Ö)|(?<=ё)|(?<=Ё)|(?<=ö)|(?<=ъ)|(?<=Ъ))ю)(?=([бвгджзклмнпрстфхцчшщйьъюёö]*(Е|И|Ü|Ö|е|и|ü|ö|YE|Ye|ye|\b))|К\b|к\b)/u', 'yü', $text); $text = preg_replace('/(\bю|(?<=[аоуыяёъАОУЫЯЁЪOo])ю)(?=([бвгджзклмнпрстфхцчшщйьъğq]*(А|Ы|У|О|Ё|Ю|а|ы|у|о|ё|ю|yo|\b))|КЪ\b|къ\b)/u', 'yu', $text); $text = str_replace('ДЖ', 'C', $text); // ДЖ $text = str_replace('дж', 'c', $text); // дж $text = preg_replace('/\bЖ/u', 'C', $text); // ^Ж $text = preg_replace('/\bж/u', 'c', $text); // ^ж $text = preg_replace('/ЗИЯ\b/u', 'ZYA', $text); // ЗИЯ^ $text = preg_replace('/зия\b/iu', 'zya', $text); // зия^ без учёта регистра $text = preg_replace('/ЛЬОН\b/u', 'LYON', $text); // ЛЬОН^ $text = preg_replace('/льон\b/iu', 'lyon', $text); // льон^ без учёта регистра $text = preg_replace('/СЬОН\b/u', 'SYON', $text); // СЬОН^ $text = preg_replace('/сьон\b/iu', 'syon', $text); // сьон^ без учёта регистра $text = preg_replace('/ЛЬЕ\b/u', 'LYE', $text); // ЛЬЕ^ $text = preg_replace('/лье\b/iu', 'lye', $text); // лье^ без учёта регистра $text = preg_replace('/(?