function urlTranslit($string)
{
$slash = "\/";
static $LettersFrom = "абвгдезиклмнопрстуфыэйхё";
static $LettersTo = "abvgdeziklmnoprstufyejxe";
static $Consonant = "бвгджзйклмнпрстфхцчшщ";
static $Vowel = "аеёиоуыэюя";
static $BiLetters = array(
"ж" => "zh", "ц"=>"ts", "ч" => "ch",
"ш" => "sh", "щ" => "sch", "ю" => "ju", "я" => "ja",
);
$string = preg_replace("/[_\s\.,?!\[\](){}]+/", "-", $string);
$string = preg_replace("/-{2,}/", "--", $string);
$string = preg_replace("/_-+_/", "--", $string);
$string = preg_replace("/[_\-]+$/", "", $string);
$string = strtolower( $string );
if (isset($GLOBALS['replacedLetters'])) {
$string = strtr($string, $GLOBALS['replacedLetters']);
};
//here we replace ъ/ь
$string = preg_replace("/(ь|ъ)([".$Vowel."])/", "j\\2", $string);
$string = preg_replace("/(ь|ъ)/", "", $string);
//transliterating
$string = strtr($string, $LettersFrom, $LettersTo );
$string = strtr($string, $BiLetters );
$string = preg_replace("/j{2,}/", "j", $string);
$string = preg_replace("/[^".$slash."0-9a-z_\-]+/", "", $string);
return $string;