从文件里读出来%u9996%u9875...之类的16进制,怎样才能正常现实为中文
2009-04-30 11:38
471 查看
从文件里读出来%u9996%u9875...之类的16进制,怎样才能正常现实为中文,在线急等!!
网友回复:各位高手,救命啊!!难道就没有人知道吗??
网友回复:iconv
网友回复:我用过了不行啊
网友回复:
PHP code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
$str = "张三";
//这两个的结果都一样:张三
print_r( iconv('', 'UTF-8', $str) );
print_r( unescape($str) );
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|.{4};|\d ;|. /U",$str,$r);
$ar = $r[0];
//print_r($ar);
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u"):
$ar[$k] = iconv("UCS-2","UTF-8",pack("H4",substr($v,-4)));
elseif(substr($v,0,3) == ""):
$ar[$k] = iconv("UCS-2","UTF-8",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == ""):
//echo substr($v,2,-1)."\r\n";
$ar[$k] = iconv("UCS-2","UTF-8",pack("n",substr($v,2,-1)));
endif;
}
return join("",$ar);
}
网友回复:我读出来是%u9996%u9875...之类的不是$str = "张三";
网友回复:md("%u9996%u9875...")试试
网友回复:我的天哪,加密也行吗??
那位老大能帮个忙啊
网友回复:
JScript code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
javascript:alert(unescape('%u9996%u9875'));
此代码浏览器地址栏运行即可...
那个是escape转换过的代码.
所以用unescape转回来就可以了.
网友回复:晕..PHP版...
那个...
9996是unicode编码...
首先把它转换成10进制,然后在对照unicode表转成值就可以了.
过程是这样滴.
JScript code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
javascript:alert(String.fromCharCode(parseInt(9996, 16)));
网友回复:9996是16进制的unicode编码...
网友回复:php中转换的!!我用iconv转怎么不行啊
网友回复:
PHP code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
<?php
$s = "%u9996%u9875";
echo(unescape($s));
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/%u.{4}|.{4};|\d ;|. /U",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,-4)));
elseif(substr($v,0,3) == "")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == "") {
$ar[$k] = iconv("UCS-2","GBK",pack("n",substr($v,2,-1)));
}
}
return join("",$ar);
}
?>
网友回复:
PHP code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
$str = "张张三%u9996%u9875";
print_r( unescape($str) );
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|.{4};?|\d ;|. /U",$str,$r);
$ar = $r[0];
print_r($ar);
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u"):
$ar[$k] = iconv("UCS-2","UTF-8",pack("H4",substr($v,-4)));
elseif(substr($v,0,3) == ""):
$ar[$k] = iconv("UCS-2","UTF-8",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == ""):
echo substr($v,2,-1)."\r\n";
$ar[$k] = iconv("UCS-2","UTF-8",pack("n",substr($v,2,-1)));
endif;
}
return join("",$ar);
}
网友回复:引用 13 楼 gzty 的回复:
PHP code
$str = "张张三%u9996%u9875";
print_r( unescape($str) );
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4}) |.{4};? |\d ; |. /U",$str,$r);
$ar = $r[0];
print_r($ar);
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u"):
$ar[$k] = iconv("UCS-2","UTF-8",pack("H4",substr($v,-4)));
…
网友回复:这种方法不行,我用对照表的方式已经弄出来了,但是觉得太笨拙了,有没有直接就把unicode字符转为iso-8859-1的方法
网友回复: {unescape}
输出编码:utf-8。
(加号) 解析为空格。
%?? 解析为单字节字符。
%u???? 解析为 unicode 字符。
PHP code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
<?php
function unescape($s) {
return preg_replace_callback('/%u([\da-fA-F]{4})/', 'unesacpe_unicode_match', urldecode($s));
}
function unesacpe_unicode_match($matches) {
return iconv('utf-16', 'utf-8', pack('H4', $matches[1]));
}
echo unescape('this is %u9996%u9875. '); // prints "this is 主页. ".
?>
网友回复:各位高手,救命啊!!难道就没有人知道吗??
网友回复:iconv
网友回复:我用过了不行啊
网友回复:
PHP code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
$str = "张三";
//这两个的结果都一样:张三
print_r( iconv('', 'UTF-8', $str) );
print_r( unescape($str) );
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|.{4};|\d ;|. /U",$str,$r);
$ar = $r[0];
//print_r($ar);
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u"):
$ar[$k] = iconv("UCS-2","UTF-8",pack("H4",substr($v,-4)));
elseif(substr($v,0,3) == ""):
$ar[$k] = iconv("UCS-2","UTF-8",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == ""):
//echo substr($v,2,-1)."\r\n";
$ar[$k] = iconv("UCS-2","UTF-8",pack("n",substr($v,2,-1)));
endif;
}
return join("",$ar);
}
网友回复:我读出来是%u9996%u9875...之类的不是$str = "张三";
网友回复:md("%u9996%u9875...")试试
网友回复:我的天哪,加密也行吗??
那位老大能帮个忙啊
网友回复:
JScript code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
javascript:alert(unescape('%u9996%u9875'));
此代码浏览器地址栏运行即可...
那个是escape转换过的代码.
所以用unescape转回来就可以了.
网友回复:晕..PHP版...
那个...
9996是unicode编码...
首先把它转换成10进制,然后在对照unicode表转成值就可以了.
过程是这样滴.
JScript code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
javascript:alert(String.fromCharCode(parseInt(9996, 16)));
网友回复:9996是16进制的unicode编码...
网友回复:php中转换的!!我用iconv转怎么不行啊
网友回复:
PHP code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
<?php
$s = "%u9996%u9875";
echo(unescape($s));
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/%u.{4}|.{4};|\d ;|. /U",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,-4)));
elseif(substr($v,0,3) == "")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == "") {
$ar[$k] = iconv("UCS-2","GBK",pack("n",substr($v,2,-1)));
}
}
return join("",$ar);
}
?>
网友回复:
PHP code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
$str = "张张三%u9996%u9875";
print_r( unescape($str) );
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|.{4};?|\d ;|. /U",$str,$r);
$ar = $r[0];
print_r($ar);
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u"):
$ar[$k] = iconv("UCS-2","UTF-8",pack("H4",substr($v,-4)));
elseif(substr($v,0,3) == ""):
$ar[$k] = iconv("UCS-2","UTF-8",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == ""):
echo substr($v,2,-1)."\r\n";
$ar[$k] = iconv("UCS-2","UTF-8",pack("n",substr($v,2,-1)));
endif;
}
return join("",$ar);
}
网友回复:引用 13 楼 gzty 的回复:
PHP code
$str = "张张三%u9996%u9875";
print_r( unescape($str) );
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4}) |.{4};? |\d ; |. /U",$str,$r);
$ar = $r[0];
print_r($ar);
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u"):
$ar[$k] = iconv("UCS-2","UTF-8",pack("H4",substr($v,-4)));
…
网友回复:这种方法不行,我用对照表的方式已经弄出来了,但是觉得太笨拙了,有没有直接就把unicode字符转为iso-8859-1的方法
网友回复: {unescape}
输出编码:utf-8。
(加号) 解析为空格。
%?? 解析为单字节字符。
%u???? 解析为 unicode 字符。
PHP code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
<?php
function unescape($s) {
return preg_replace_callback('/%u([\da-fA-F]{4})/', 'unesacpe_unicode_match', urldecode($s));
}
function unesacpe_unicode_match($matches) {
return iconv('utf-16', 'utf-8', pack('H4', $matches[1]));
}
echo unescape('this is %u9996%u9875. '); // prints "this is 主页. ".
?>
相关文章推荐
- 怎样才能判断出用户上传的文件中没有包含木马以及恶意病毒之类
- 怎样才能判断出用户上传的文件中没有包含木马以及恶意病毒之类
- 怎样才能在VS2010中打开VS2008创建的net3.5的项目而不用升级文件呢?升级后再回到VS2008还能正常打开吗?
- 安装完eclipse,dbwear后,需要在他们解压文件.ini下加上你liux的jdk的安装路径,才能正常使用
- 怎样将shp文件的坐标点导出来?
- IO流 字符流(FileReader)读数据 把文件本身中的内容读出来(字符流能打印出中文)
- jasperreports-5.6 + jaspersoftstudio-5.6 生成pdf 文件中文无法正常显示问题
- 怎样才能够修改PDF文件中的文字大小
- linux下使用mysql,查询出来的结果中文显示不正常的解决方案
- c# 导入excel 日期为整形如何处理?读出来是一个数值,如2008-08-08读出来是39688,怎样才能读出来是日期格式。
- 怎样才能把pdf文件转换成jpg
- rust.vim文件放到什么地方,vim才能正常识别Rust
- 怎样才能把excel格式文件转换成pdf文件?
- 怎样才能使用C语言编程生成的exe文件运行后不立刻结束
- 打开 Excel文件, Excel不显示窗口来,还要在Excel文件中再提取一次才能显示出来
- 单击table 表中任意一行,怎样才能把该行号读出来
- jspsmart 下载文件不支持中文 升级使其另存为时显示中文,但打开时还是乱码(已修改正常)
- 怎样才能算是设计优秀的PCB文件
- java文件在eclipse工程里中文显示方框乱码,用记事本中打开显示正常
- 搜索一个类的dispose的调用,把其他类的dispose方法都搜出来了,怎样才能把这个dispose的真正调用搜出来呢?