PhpmysqlUTF-8 coding problems

Source: Internet
Author: User
PhpmysqlUTF-8 coding problems have such a UTF-8 code "\ xe6 \ x93 \ x8d \ xe4 \ xbd \ x9c"
It is correct to directly assign values to the output in the page.
$ Subject = "\ xe6 \ x93 \ x8d \ xe4 \ xbd \ x9c ";
$ Subject = mb_convert_encoding ($ subject, "GB2312", "UTF-8 ");
Echo $ subject;
?>
However, the record is stored in the database. the input is still "\ xe6 \ x93 \ x8d \ xe4 \ xbd \ x9c ";
Which of the following has encountered a similar problem? please advise. thank you.


Reply to discussion (solution)

Do not understand what you want to express

Let's take a look at the encoding of your database. it's not estimated that it's GB2312.

"\ Xe6 \ x93 \ x8d \ xe4 \ xbd \ x9c" in the program"
A representation of the hexadecimal internal code of UTF-8 encoding operations (it must be enclosed by double quotation marks)
Otherwise, it's just a string like \ xe6 \ x93 \ x8d \ xe4 \ xbd \ x9c.

Only those written in the program will be converted, and none of others will.
You can convert the string \ xe6 \ x93 \ x8d \ xe4 \ xbd \ x9c in this way.

$s = '\xe6\x93\x8d\xe4\xbd\x9c';echo hex2bin(str_replace('\x', '', $s));echo urldecode(str_replace('\x', '%', $s));

"\ Xe6 \ x93 \ x8d \ xe4 \ xbd \ x9c" in the program"
A representation of the hexadecimal internal code of UTF-8 encoding operations (it must be enclosed by double quotation marks)
Otherwise, it's just a string like \ xe6 \ x93 \ x8d \ xe4 \ xbd \ x9c.

Only those written in the program will be converted, and none of others will.
You can convert the string \ xe6 \ x93 \ x8d \ xe4 \ xbd \ x9c in this way.

$s = '\xe6\x93\x8d\xe4\xbd\x9c';echo hex2bin(str_replace('\x', '', $s));echo urldecode(str_replace('\x', '%', $s));


As the moderator said, this is correct. thank you!

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.