LAMP garbled problem summary

Source: Internet
Author: User
Sometimes there will be garbled characters, and sometimes someone may ask questions about garbled text. for the purpose of review and weeding, sort it out. At first, you may be confused about the garbled problem, but you can easily avoid or solve it after learning about several possible garbled points. Here the garbled problem is generally divided into two... "> <LINKhref =" http://www.php100.com//statics/style/headflo

 

Sometimes there will be garbled characters, and sometimes someone may ask questions about garbled text. for the purpose of review and weeding, sort it out. At first, you may be confused about the garbled problem, but you can easily avoid or solve it after learning about several possible garbled points.

The garbled problem mentioned here is generally divided into two categories:

1. garbled characters appear on the page;

2. garbled characters appear during database values or inserts;

The best way to avoid garbled characters is to specify the same encoding in all specified encoding places. We recommend that you use UTF-8 for unified encoding. The following describes and explains three garbled characters.

In the first case, database operations are not involved, or we assume that database operations will not cause garbled code (the case of database garbled code is discussed below ). You only need to check whether the encoding of the script file is consistent with the page encoding. File encoding can be changed in common text editors, such as Eclipse, notepad2, and Netbeans, while the webpage page encoding is specified through the meta tag.
<Meta content = "text/html; charset = UTF-8 & Prime; http-equiv =" Content-Type "/>

In the second case, the encoding of the field in the database, the encoding of the field in the database table, and the page encoding must be consistent. Database encoding and field encoding can be specified by setting collation during creation. Page encoding as mentioned above.

Sometimes, when we perform database operations, what characters are inserted and those characters are still read, it seems that there is no problem. However, when we manage databases, garbled characters are displayed in third-party tools. This is because the encoding used to connect to the database is inconsistent with the database encoding or page encoding. After the database connection is established, we can use an SQL statement to specify the encoding: SET NAMES UTF8. Note that there is no hyphen.

To sum up, we recommend that you specify all the encodings as UTF-8.
Script File encoding: UTF-8
Webpage code:
<Meta content = "text/html; charset = UTF-8 & Prime; http-equiv =" Content-Type "/>
Database and Field Encoding: utf8_general_ci
Database Connection Code: set names UTF8;

Digress: Why UTF8 encoding is recommended? The only thing I remember is that it is an international language code that is compatible with other languages. The following is a professional description:

The only benefit of using UTF-8 encoding is that foreign users can view any web page of UTF-8 encoding, whether Chinese, Japanese, Korean, or Arabic, if using Windows XP English version, it can be displayed normally, UTF-8 is the world's general language encoding, UTF-8 promotion to the application of Google, and Blog developers. If you use IE6.0 in Windows XP to browse the gb2312 webpage, you will be prompted to install the language pack. Therefore, many overseas visitors may be lost.

The advantage of using gb2312 encoding is that because the webpage text generated by the program uses the ANSI encoding format, it will save some size than the UTF-8 text encoding, the access speed will be a little faster, for more information about the volume ratio, see the exact experiment here.

Let's take a look at the Japanese Blog, the use of Japan (EUC) encoding, UTF-8 encoding are the majority; Korean Blog, UTF-8 encoding accounted for the majority, Korean (EUC), Korean also accounted for a majority.

It can be concluded that the use of UTF-8 language encoding, or the use of their own language encoding, and whether there is no much relationship with patriotism, or, the root of it does not matter, in China, no one is not patriotic. I 've been wandering between UTF-8 and gb2312, do you want to use UTF-8 encoding? Tens of millions of questions.

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.