public static function toLatin($string, $separator = '', $clean = false)
{
$cyrillicCount = count(self::$cyr);
for ($i = 0; $i < $cyrillicCount; $i++) {
$string = str_replace(self::$cyr[$i], self::$lat[$i], $string);
}
$string = preg_replace("/([qwrtpsdfghklzxcvbnmQWRTPSDFGHKLZXCVBNM]+)[jJ]e/", "\${1}e", $string);
$string = preg_replace("/([qwrtpsdfghklzxcvbnmQWRTPSDFGHKLZXCVBNM]+)[jJ]/", "\${1}y", $string);
$string = preg_replace("/([eyuioaEYUIOA]+)[Kk]h/", "\${1}h", $string);
$string = preg_replace("/^kh/", "h", $string);
$string = preg_replace("/^Kh/", "H", $string);
$string = trim($string);
if (empty($separator) === false) {
$string = str_replace(' ', $separator, $string);
$string = preg_replace('/[' . $separator . ']{2,}/', '', $string);
}
if ($clean !== false) {
$string = strtolower($string);
$string = preg_replace('/[^-_a-z0-9.]+/', '', $string);
}
return $string;
}