Iconv:iconv_open (Ptocharset, Pfromcharset); Additional parameters for//ignore

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.