Converting PHPgb2312 to UTF-8 does not use iconv, which is unreliable.

Source: Internet
Author: User
Convert PHPgb2312 to UTF-8 without using iconv, this unreliable iconv ("GB2312", "UTF-8 // IGNORE", $ str );
It is easy to lose words and unstable. if there is no "// IGNORE", it will not be displayed after an error.
Are there other feasible methods?


Reply to discussion (solution)

Try
Mb_convert_encoding

Generally, GBK is used instead of gb2312. there are too few Chinese characters encoded in gb2312.
Charset = gb2312 is used on the webpage. In fact, the browser still calls GBK, so do not mistakenly think that gb2312 can display most Chinese characters.

Impossible! The entire gb2312 is contained in UTF-8, and it is impossible to lose words.
You throw the word because you have processed the gbk character as gb2312.

Try
Mb_convert_encoding

Not feasible.

Php implements mutual conversion between UTF-8 and gb2312 encoding
Php does not use the iconv library for gb2312 and UTF-8 encoding conversion functions

We hope that the above two articles will help you solve your current problems.

Not easy to use .. On the fifth floor

You 'd better post the text.

For example, in MSSQL ",
If iconv ("GB2312", "UTF-8", $ str );
The output is: "XXX Jin"
Iconv ("GB2312", "UTF-8 // IGNORE", $ str );
The output is: "XXX Jin {xx address of the park"

I checked iconv online and found a small BUG. A single character is lost.

$ Str = "XXX Jin Huiyuan address ";
Echo iconv ('gb2312', 'utf-8', $ str); // address of a certain jinhuiyuan
Echo iconv ('gbk', 'utf-8', $ str); // address of a certain jinhuiyuan

No problem
If there is a problem in your environment, you can only say that your php version is too low.

For example, in MSSQL ",
If iconv ("GB2312", "UTF-8", $ str );
The output is: "XXX Jin"
Iconv ("GB2312", "UTF-8 // IGNORE", $ str );
The output is: "XXX Jin {xx address of the park"

I checked iconv online and found a small BUG. A single character is lost.

$ Str = "XX Jin Huiyuan xx address"; echo iconv ("GB2312", "UTF-8", $ str); echo iconv ("GB2312", "UTF-8 // IGNORE ", $ str );

My side is normal.

Of course.
I saved this address in the database of GB2312 at the address of a XXX Jin Huiyuan. The problem occurred when I read it.

XX Jin Huiyuan xx address is bg2312 code stored outside
The currently processed page is utf-8. pay attention to this difference.

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.