PHP page Chinese garbled analysis _php skills

Source: Internet
Author: User

PHP page garbled appearance of a number of reasons, one is the page encoding does not count one, the second is the database does not set the code, the third is the Apache coding problem, I would like to introduce two solutions, the overall is the page code is not unified.
Most of the garbled is due to inconsistent coding methods, of which there are four major inconsistencies may exist this possibility:
1, the page file encoding method (. html,.php, etc.)
2, the html.head of the specified browser encoding method
3, the MySQL database transmission coding mode
4. Apache Character Set

In only PHP code page, do JS window, if the window content contains Chinese, there may be garbled problems,
Workaround, one line of code:
Page Chinese garbled

Copy Code code as follows:

Header ("content-type:text/html; Charset=utf-8 ");

Database is garbled
Copy Code code as follows:

. <?php
mysql_query (' SET NAMES UTF8 ');
The next thing is to identify the data or modify it, increase it
?>

Attention:
1, this code must be placed at the top of the file, ' <?php ' after;
2, CharSet value to see the entire site code, if it is gb2312, then fill in the gb2312.

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.