Today, when converting a file, Iconv () always returns-1, prompting the encoding conversion to fail.
Altogether more than 30 files, the original code is the same, why some conversion will fail, return-1?
Search the Internet for a moment, find an accompanying parameter: //ignore
It is best to add //ignore after the first parameter of Iconv_open ().
Official usage: Iconv_open ("GBK", "utf-8"); Convert Utf-8 to GBK
In the actual operation, it is necessary (preferably) to add "//ignore" after the 1th parameter, namely: Iconv_open ("Gbk//ignore", "utf-8");
After I add//ignore, test again, sure enough iconv () no longer returns-1
File source code: Utf-8, want to convert to GBK
So if I use a wrong code, just add//ignore, won't it return-1:
Iconv_open ("Gbk//ignore", "utf-16"); The wrong utf-16 is deliberately used here.
Test Result: Iconv () return-1
I'm relieved of that.
Another search for the relevant information, the meaning of//ignore: (http://hi.baidu.com/breezelark/item/af7ec615c9588bd8be90427c)
Add://ignore
If you encounter a character that cannot be converted, you discard it directly and then continue the conversion.
Default does not add://ignore
If you encounter characters that cannot be converted, truncate directly from the first illegal character and throw notice (notification), ICONV () returns-1.
2014-07-02
Iconv:iconv_open (Ptocharset, Pfromcharset); Additional parameters for//ignore