function mem_urlencode($str) {
global $langdata;
if (isset($langdata['url_pat']) AND @sizeof($langdata['url_pat']) == @sizeof($langdata['url_rep'])) {
$str = preg_replace($langdata['url_pat'],$langdata['url_rep'],$str);
}
$alias = preg_replace('/&#x([0-9a-f]{1,7});/ei', 'chr(hexdec("\1"))', $str);
$alias = preg_replace('/&#([0-9]{1,7});/e', 'chr("\1")', $alias);
if (preg_match("/[а-яё]+/i",$alias)) {
static $replace_array = array(
'а' => 'a', 'б' => 'b', 'в' => 'v',
'г' => 'g', 'д' => 'd', 'е' => 'e',
'ё' => 'yo', 'ж' => 'zh', 'з' => 'z',
'и' => 'i', 'й' => 'j', 'к' => 'k',
'л' => 'l', 'м' => 'm', 'н' => 'n',
'о' => 'o', 'п' => 'p', 'р' => 'r',
'с' => 's', 'т' => 't', 'у' => 'u',
'ф' => 'f', 'х' => 'h', 'ц' => 'c',
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch',
'ь' => '7o', 'ы' => 'y', 'ъ' => '#',
'э' => 'je', 'ю' => 'ju', 'я' => 'ja',
'А' => 'A', 'Б' => 'B', 'В' => 'V',
'Г' => 'G', 'Д' => 'D', 'Е' => 'E',
'Ё' => 'YO', 'Ж' => 'ZH', 'З' => 'Z',
'И' => 'I', 'Й' => 'J', 'К' => 'K',
'Л' => 'L', 'М' => 'M', 'Н' => 'N',
'О' => 'O', 'П' => 'P', 'Р' => 'R',
'С' => 'S', 'Т' => 'T', 'У' => 'U',
'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C',
'Ч' => 'CH', 'Ш' => 'SH', 'Щ' => 'SCH',
'Ь' => '7o', 'Ы' => 'Y', 'Ъ' => '#',
'Э' => 'JE', 'Ю' => 'JU', 'Я' => 'JA',
'&' => 'and',''' => '', '(' => '(', ')' => ')', ':' => ':'
);
$alias = strtr($alias, $replace_array);
$alias = strip_tags($alias); // strip HTML
//$alias = preg_replace('/[^.%A-Za-z0-9 _-]/', '', $alias); // strip non-alphanumeric characters
$alias = preg_replace('/s+/', ' ', $alias); // convert white-space to dash
$alias = preg_replace('/-+/', '-', $alias); // convert multiple dashes to one
$alias = trim($alias, '-'); // trim excess
$str = 'ru-'.$alias;}
return urlencode($str);
}
function mem_deurlencode($str) {
global $langdata;
if (isset($langdata['url_pat']) AND @sizeof($langdata['url_pat']) == @sizeof($langdata['url_rep'])) {
$str = preg_replace($langdata['url_pat'],$langdata['url_rep'],$str);
}
// Convert all numeric entities to their actual character
$alias = preg_replace('/&#x([0-9a-f]{1,7});/ei', 'chr(hexdec("\1"))', $str);
$alias = preg_replace('/&#([0-9]{1,7});/e', 'chr("\1")', $alias);
if (preg_match ("/bru-b/", $alias)) {
static $replace_array = array(
'ru-'=>'',
'a'=>'а' , 'b'=>'б' , 'v'=>'в',
'g'=>'г', 'd'=>'д' , 'e'=>'е' ,
'yo'=>'ё' , 'zh'=>'ж' , 'z'=>'з' ,
'i'=>'и' , 'j'=>'й' , 'k'=>'к' ,
'l'=>'л' , 'm'=>'м' , 'n'=>'н' ,
'o'=>'о' , 'p'=>'п' , 'r'=>'р' ,
's'=>'с' , 't'=>'т' , 'u'=>'у' ,
'f'=>'ф' , 'h'=>'х' , 'c'=>'ц' ,
'ch'=>'ч' , 'sh'=>'ш' , 'sch'=>'щ' ,
'7o'=>'ь' , 'y'=>'ы' , '#'=>'ъ' ,
'je'=>'э' , 'ju'=>'ю' , 'ja'=>'я' ,
'A'=>'А' , 'B'=>'Б' , 'V'=>'В' ,
'G'=>'Г' , 'D'=>'Д' , 'E'=>'Е' ,
'YO'=>'Ё' , 'ZH'=>'Ж' , 'Z'=>'З' ,
'I'=>'И' , 'J'=>'Й' , 'K'=>'К' ,
'L'=>'Л' , 'M'=>'М' , 'N'=>'Н' ,
'O'=>'О' , 'P'=>'П' , 'R'=>'Р' ,
'S'=>'С' , 'T'=>'Т' , 'U'=>'У' ,
'F'=>'Ф' , 'H'=>'Х' , 'C'=>'Ц' ,
'CH'=>'Ч' , 'SH'=>'Ш' , 'SCH'=>'Щ' ,
'7o'=>'Ь' , 'Y'=>'Ы' , '#'=>'Ъ' ,
'JE'=>'Э' , 'JU'=>'Ю' , 'JA'=>'Я' ,
'&' => 'and',''' => '', '(' => '(', ')' => ')', ':' => ':'
);
$alias = strtr($alias, $replace_array);
$str = trim($alias, '-'); // trim excess
}
return $str;
}
//Added in 3.8.5
function mem_urldecode($str) {
return urldecode($str);
} |