所属分类:PHP工具与代码
用于解密形如
[code]\u0068\u0074\u0074\u0070\u003a\u002f\u002f\u0036\u0031\u002e\u0031\u0033\u0036\u002e\u0031\u0035\u0032\u002e\u0035\u0035\u002f\u0073\u0061\u006e\u0067\u0075\u006f\u0067\u0061\u006d\u0065\u002f\u0064\u006f\u0077\u006e\u006c\u006f\u0061\u0064\u002f\u0070\u0061\u0074\u0063\u0068\u002f\u0073\u0061\u006e\u0039\u0039\u002e\u0039\u002f\u0073\u0061\u006e\u0039\u002d\u0065\u0064\u0069\u0074\u006f\u0072\u002d\u0030\u0039\u002d\u0076\u0031\u002e\u0030\u002e\u0072\u0061\u0072[/code]加密后的字符串
[code]<?php
function uni_decode($s) {
preg_match_all('/\&\#([0-9]{2,5})\;/', $s, $html_uni);
preg_match_all('/[\\\%]u([0-9a-f]{4})/ie', $s, $js_uni);
$source = array_merge($html_uni[0], $js_uni[0]);
$js = array();
for($i=0;$i<count($js_uni[1]);$i++) {
$js[] = hexdec($js_uni[1][$i]);
}
$utf8 = array_merge($html_uni[1], $js);
$code = $s;
for($j=0;$j<count($utf8);$j++) {
$code = str_replace($source[$j], unicode2utf8($utf8[$j]), $code);
}
return $code;//$s;//preg_replace('/\\\u([0-9a-f]{4})/ie', "chr(hexdec('\\1'))", $s);
}
function unicode2utf8($c) {
$str="";
if ($c < 0x80) {
$str.=chr($c);
} else if ($c < 0x800) {
$str.=chr(0xc0 | $c>>6);
$str.=chr(0x80 | $c & 0x3f);
} else if ($c < 0x10000) {
$str.=chr(0xe0 | $c>>12);
$str.=chr(0x80 | $c>>6 & 0x3f);
$str.=chr(0x80 | $c & 0x3f);
} else if ($c < 0x200000) {
$str.=chr(0xf0 | $c>>18);
$str.=chr(0x80 | $c>>12 & 0x3f);
$str.=chr(0x80 | $c>>6 & 0x3f);
$str.=chr(0x80 | $c & 0x3f);
}
return $str;
}
//$str='\u0068\u0074\u0074\u0070\u003a\u002f\u002f\u0036\u0031\u002e\u0031\u0033\u0036\u002e\u0031\u0035\u0032\u002e\u0035\u0035\u002f\u0073\u0061\u006e\u0067\u0075\u006f\u0067\u0061\u006d\u0065\u002f\u0064\u006f\u0077\u006e\u006c\u006f\u0061\u0064\u002f\u0070\u0061\u0074\u0063\u0068\u002f\u0073\u0061\u006e\u0039\u0039\u002e\u0039\u002f\u0073\u0061\u006e\u0039\u002d\u0065\u0064\u0069\u0074\u006f\u0072\u002d\u0030\u0039\u002d\u0076\u0031\u002e\u0030\u002e\u0072\u0061\u0072';
//echo uni_decode($str); // 大家好,我是孤魂!这是测试文本!
$download=uni_decode($download);
//下载地址 解码 unicode 字符结束
?>[/code]
注意解码完后的编码为UTF-8格式,如需要还转换为GB2312中文编码
[code]\u0068\u0074\u0074\u0070\u003a\u002f\u002f\u0036\u0031\u002e\u0031\u0033\u0036\u002e\u0031\u0035\u0032\u002e\u0035\u0035\u002f\u0073\u0061\u006e\u0067\u0075\u006f\u0067\u0061\u006d\u0065\u002f\u0064\u006f\u0077\u006e\u006c\u006f\u0061\u0064\u002f\u0070\u0061\u0074\u0063\u0068\u002f\u0073\u0061\u006e\u0039\u0039\u002e\u0039\u002f\u0073\u0061\u006e\u0039\u002d\u0065\u0064\u0069\u0074\u006f\u0072\u002d\u0030\u0039\u002d\u0076\u0031\u002e\u0030\u002e\u0072\u0061\u0072[/code]加密后的字符串
[code]<?php
function uni_decode($s) {
preg_match_all('/\&\#([0-9]{2,5})\;/', $s, $html_uni);
preg_match_all('/[\\\%]u([0-9a-f]{4})/ie', $s, $js_uni);
$source = array_merge($html_uni[0], $js_uni[0]);
$js = array();
for($i=0;$i<count($js_uni[1]);$i++) {
$js[] = hexdec($js_uni[1][$i]);
}
$utf8 = array_merge($html_uni[1], $js);
$code = $s;
for($j=0;$j<count($utf8);$j++) {
$code = str_replace($source[$j], unicode2utf8($utf8[$j]), $code);
}
return $code;//$s;//preg_replace('/\\\u([0-9a-f]{4})/ie', "chr(hexdec('\\1'))", $s);
}
function unicode2utf8($c) {
$str="";
if ($c < 0x80) {
$str.=chr($c);
} else if ($c < 0x800) {
$str.=chr(0xc0 | $c>>6);
$str.=chr(0x80 | $c & 0x3f);
} else if ($c < 0x10000) {
$str.=chr(0xe0 | $c>>12);
$str.=chr(0x80 | $c>>6 & 0x3f);
$str.=chr(0x80 | $c & 0x3f);
} else if ($c < 0x200000) {
$str.=chr(0xf0 | $c>>18);
$str.=chr(0x80 | $c>>12 & 0x3f);
$str.=chr(0x80 | $c>>6 & 0x3f);
$str.=chr(0x80 | $c & 0x3f);
}
return $str;
}
//$str='\u0068\u0074\u0074\u0070\u003a\u002f\u002f\u0036\u0031\u002e\u0031\u0033\u0036\u002e\u0031\u0035\u0032\u002e\u0035\u0035\u002f\u0073\u0061\u006e\u0067\u0075\u006f\u0067\u0061\u006d\u0065\u002f\u0064\u006f\u0077\u006e\u006c\u006f\u0061\u0064\u002f\u0070\u0061\u0074\u0063\u0068\u002f\u0073\u0061\u006e\u0039\u0039\u002e\u0039\u002f\u0073\u0061\u006e\u0039\u002d\u0065\u0064\u0069\u0074\u006f\u0072\u002d\u0030\u0039\u002d\u0076\u0031\u002e\u0030\u002e\u0072\u0061\u0072';
//echo uni_decode($str); // 大家好,我是孤魂!这是测试文本!
$download=uni_decode($download);
//下载地址 解码 unicode 字符结束
?>[/code]
注意解码完后的编码为UTF-8格式,如需要还转换为GB2312中文编码