不是iconv函数的bug
filed in Uncategorized on Sep.24, 2009
上一篇把题目写成《iconv函数的小bug》怪吓人的~~~华晨同学的回复使我感到自己的不求甚解.正所谓知错能改,善莫大焉。于是我重新查了一遍:php官方的说明:http://cn.php.net/manual/en/function.iconv.php
函数原型: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的时候,当目标输出的编码不认识的时候则什么也不操作;什么都不加的时候则会报错~~~
手册里面有个非常生动的例子:
59cff78c6fd1869de38b71e7d81beb73000
输出结果是:
Original :