Summary of PHP and MySQL garbled issues

Source: Internet
Author: User
It completely solves the issue of PHP and MySQL garbled characters, because some people often ask this question recently, so I will simply summarize and send an article here, and then let him see it directly on his website. it is annoying to answer the same question many times.

The solution is very simple, is to unified encoding, if we use UTF-8 encoding:
1. Create a databaseIf you want to publish this article, please indicate the location, without the right to publish the copyright, I do not like to see that kind of website my work does not indicate the person qq9256114
When the database is created, the encoding is set to utf8 in a unified manner. When you create a data table or add a field, do not set encoding again.

2. Add page Encoding
PHP
Header ('content-type: text/html; charset = UTF-8 ');

Html
<Meta http-equiv = "Content-Type"Content= "Text/html; charset = UTF-8"/>
<Title> must be placed before the title </title>If you want to publish this article, please indicate the location, without the right to publish the copyright, I do not like to see that kind of website my work does not indicate the person qq9256114

3. When establishing a connection with a database
Mysql_query ("set names 'utf8 '");
Mysql_select_db ('table name', $ this-> conn) or die ('Open the databaseError, Please check the database exists! ');

4. When saving the PHP File

Taking editplus as an example, you must select UTF-8 as the encoding when saving.

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.