不是iconv函数的bug
2010-01-16 12:57
176 查看
函数原型:string iconv ( string $in_charset , string $out_charset , string $str )
特别是第二个参数说明:
The output charset.
If you append the string //TRANSLIT to out_charset transliteration is activated. This means that when a character can’t be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, str is cut from the first illegal character and an E_NOTICE is generated.
意思是如果你在第二个参数后面加上//TRANSLIT ,这样的话,当遇到目标输出的编码不认识的字符的时候,能被一个或几个近似的字符代替;而如果在第二个参数后面加上//IGNORE的时候,当目标输出的编码不认识的时候则什么也不操作;什么都不加的时候则会报错~~~
手册里面有个非常生动的例子:
<?php
$text = "This is the Euro symbol '€'.";
echo 'Original : ', $text, PHP_EOL;
echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL;
echo 'IGNORE : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL;
echo 'Plain : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL;
?>
输出结果是:
Original : This is the Euro symbol ‘€’.
TRANSLIT : This is the Euro symbol ‘EUR’.
IGNORE : This is the Euro symbol ”.
Plain :
Notice: iconv(): Detected an illegal character in input string in ./iconv-example.php on line 7
This is the Euro symbol ‘
这样就非常清楚了
这里总结几点教训:
第一:php最好的手册就是官方的在线收藏;
(网上下的php中文手册往往会不完整或者没有更新,开始就是因为我电脑上的php中文手册没有这几个参数的说明)
第二:别太相信百度、google的中文搜索结果,别人讲的不一定是对的~~
最好就是直接找最权威,最官方的说明~~
特别是第二个参数说明:
The output charset.
If you append the string //TRANSLIT to out_charset transliteration is activated. This means that when a character can’t be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, str is cut from the first illegal character and an E_NOTICE is generated.
意思是如果你在第二个参数后面加上//TRANSLIT ,这样的话,当遇到目标输出的编码不认识的字符的时候,能被一个或几个近似的字符代替;而如果在第二个参数后面加上//IGNORE的时候,当目标输出的编码不认识的时候则什么也不操作;什么都不加的时候则会报错~~~
手册里面有个非常生动的例子:
<?php
$text = "This is the Euro symbol '€'.";
echo 'Original : ', $text, PHP_EOL;
echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL;
echo 'IGNORE : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL;
echo 'Plain : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL;
?>
输出结果是:
Original : This is the Euro symbol ‘€’.
TRANSLIT : This is the Euro symbol ‘EUR’.
IGNORE : This is the Euro symbol ”.
Plain :
Notice: iconv(): Detected an illegal character in input string in ./iconv-example.php on line 7
This is the Euro symbol ‘
这样就非常清楚了
这里总结几点教训:
第一:php最好的手册就是官方的在线收藏;
(网上下的php中文手册往往会不完整或者没有更新,开始就是因为我电脑上的php中文手册没有这几个参数的说明)
第二:别太相信百度、google的中文搜索结果,别人讲的不一定是对的~~
最好就是直接找最权威,最官方的说明~~
相关文章推荐
- CSS魔法堂:"那不是bug,是你不懂我!" by inline-block
- C专家编程——这不是Bug,而是语言特性
- 不是Bug的bug-CUDA程序显卡驱动在2秒以后恢复
- TextBox.Multiline缩进现象不是bug(文档解读,帮助你理解MSDN难懂的词句)
- 微软雅黑字体的bug,可能不是我第一个发现的
- [原创]分享IE7一个神奇的BUG(不是封闭标签的问题,的确是IE7的BUG)
- 给mantis添加新状态比如重开跟这不是bug
- 子查询中包含不存在的列--居然不是bug!
- Why bugs don’t get fixed? 不是所有的Bug都要修复
- 我是BIOS工程师,我不是解Bug工程师……
- 与端口冲突有关的一个低概率bug的定位过程(这次不是360的错啊)---浅谈bind()函数返回失败
- 这不是bug,而是特性(uva 658)
- Bug3 ---error C2039: “SetWindowTextA”: 不是“ATL::CStringT<BaseType,StringTraits>”的成员
- 不是bug的bug,从svn下的”错误“代码。
- [转]敏捷就循环往复的不断改进 & 测试不是寻找Bug的游戏 & 成功实施敏捷的十二种模式
- mfc中0xC015000F:正在被停用的激活上下文不是最近激活的bug
- 再锻炼,有新发现 Math.random() * n vs Random.nextInt(): 这不是Bug?
- 那不是Bug,是新需求
- qt5集成libcurl实现tftp和ftp的方法之三:搭建FTP时,当ftpServer端默认登录的目录不是根目录/时,有一个bug会产生的解决办法
- .net datagrid.datasource绑定不知道算不是算BUG