函数原型: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的时候,当目标输出的编码不认识的时候则什么也不操作;什么都不加的时候则会报错~~~
手册里面有个非常生动的例子:
输出结果是:
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的中文搜索结果,别人讲的不一定是对的~~
最好就是直接找最权威,最官方的说明~~