中文编码(decode)的问题
时间:2010-08-14
来源:互联网
decode文档这样描述:
When you run $string = decode("utf8", $octets) , then $string may not be equal to $octets. Though they both contain the same data, the UTF8 flag for $string is on unless $octets entirely consists of ASCII data (or EBCDIC on EBCDIC machines). See The UTF8 flag below.
网上也有中文描述:
$string = decode(ENCODING, $octets [, CHECK]) 把字符串从其他编码转成utf8编码, 并开启utf8 flag, 不过有个例外就是, 如果字符串是仅仅ascii编码或EBCDIC编码的话, 不开启utf8 flag.
我测试了一下:
#!/usr/bin/perl -w
use Encode;
$str0="cn";
$str=Encode::decode("utf8",$str0);
#Encode::_utf8_off($str);
print "str0:Yes\n" if(Encode::is_utf8($str0));
print "str:Yes\n" if(Encode::is_utf8($str));
输出结果:
str:Yes
难道asicc也开启了utf8 flag?
还有个问题就是:
use utf8;
use encoding "utf8";
有什么区别?
When you run $string = decode("utf8", $octets) , then $string may not be equal to $octets. Though they both contain the same data, the UTF8 flag for $string is on unless $octets entirely consists of ASCII data (or EBCDIC on EBCDIC machines). See The UTF8 flag below.
网上也有中文描述:
$string = decode(ENCODING, $octets [, CHECK]) 把字符串从其他编码转成utf8编码, 并开启utf8 flag, 不过有个例外就是, 如果字符串是仅仅ascii编码或EBCDIC编码的话, 不开启utf8 flag.
我测试了一下:
#!/usr/bin/perl -w
use Encode;
$str0="cn";
$str=Encode::decode("utf8",$str0);
#Encode::_utf8_off($str);
print "str0:Yes\n" if(Encode::is_utf8($str0));
print "str:Yes\n" if(Encode::is_utf8($str));
输出结果:
str:Yes
难道asicc也开启了utf8 flag?
还有个问题就是:
use utf8;
use encoding "utf8";
有什么区别?
作者: better0332 发布时间: 2010-08-14
use utf8 是开启 perl unicode的支持不会去转换的。
而 use encoding "utf8" 则是将代码转换成 utf-8的去处理的
如 两个 unicode的字符连接后如果不使用
use encoding "utf8" 那么结果就是 latin-1
以上是我的理解了
perldoc上有说明的
而 use encoding "utf8" 则是将代码转换成 utf-8的去处理的
如 两个 unicode的字符连接后如果不使用
use encoding "utf8" 那么结果就是 latin-1
以上是我的理解了

perldoc上有说明的
作者: redskywy 发布时间: 2010-08-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28