Php, ajax, mysql, latin1 encoding problems

Source: Internet
Author: User
Php, ajax, mysql, latin1 encoding problem mysql default latin1 encoding, read garbled characters when reading data using ajax, ajax on the server side. php involves the encoding. header (& #39; Content-type: & nbsp; text/xml; charset = utf-8 & #39;); encoding of php, ajax, mysql, latin1
Mysql uses latin1 encoding by default. garbled characters are read when ajax is used to read data. in ajax. php on the server, the encoding is involved in these two aspects:

A. header ('content-type: text/xml; charset = utf-8 ');
B. added mysql_query ("set names 'utf8'") during query '");

In addition, ajax. php is UTF-8 encoded.

Records can be queried, but the XML source code can be viewed as follows:
2?

I have tried many types of encoding conversion and all failed. please help me !!!!!

------ Solution --------------------
Try to add UTF-8 encoding to xml
------ Solution --------------------
Mysql default latin1 encoding to UTF-8
Use UTF-8 for client html
It is OK as long as it can be normally displayed on the client, regardless of the Xiami sample.
------ Solution --------------------
Do not use LATIN1 for multi-byte characters. UTF8 or GBK is recommended
------ Solution --------------------
It is best to unify the encoding format ~~
------ Solution --------------------
Can I use iconv () for unified encoding;
------ Solution --------------------
B. added mysql_query ("set names 'utf8'") during query '");

It should be mysql_query ("set names 'utf-8.

Ajax. php uses iconv () to output XML code.

$ Xml = "xml data to be output ";

Echo iconv ("latin1", "UTF-8", $ xml );

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.