Lamp garbled Problem Summary article

Source: Internet
Author: User
Tags advantage

Occasionally will encounter garbled, and sometimes someone will ask garbled problem, for the purpose of review and weeding, tidy up. Just start to encounter garbled problem may be overwhelmed, but in understanding may appear garbled several points, it can easily avoid or solve.

The garbled problem here is divided into two categories:

One, the page appears garbled;

Second, from the database value or insert when garbled;

The best way to avoid garbled code is to specify the same encoding wherever you specify the encoding. It is recommended to use UTF-8 for unified coding. The following description and explain the above three kinds of garbled situation.

The first case, does not involve database operation, or we assume that the operation of the database will not cause garbled (the database causes garbled situation in the following discussion). Then you just need to check that the script file's encoding and page encoding are consistent. File encoding General text editors can change, such as Eclipse,notepad2,netbeans, and the page's encoding is specified by the META tag.
< meta content= "text/html; charset=utf-8″http-equiv= "Content-type"/>

In the second case, you need the database encoding, the encoding of the field in the database table, and the page encoding to remain consistent. Database encoding and field encoding can be specified at the time of creation by setting collation. Page encoding has been mentioned above.

Sometimes, we are in the database operation, what characters are inserted, read out the time or those characters, as if there is no problem. But when we manage the database, the third party tool is displayed in garbled. This is due to the encoding of the connection database and the encoding of the database or the inconsistent page encoding. We can specify the encoding via SQL statements after the database connection is established: Set NAMES UTF8, and note that there are no hyphens.

Summary: The recommended approach here is to designate all encodings as utf-8.
Script file Encoding: Utf-8
Page page encoding:
< meta content= "text/html; charset=utf-8″http-equiv= "Content-type"/>
Database and field code: UTF8_GENERAL_CI
Database Connection code: SET NAMES UTF8;

Digression: Why is it recommended to use UTF8 encoding? The only thing I remember is that it is the international language coding, compatibility is better, so use it. Here's a professional note:

The only advantage of using UTF-8 encoding is that foreign users who use the English version of Windows XP to browse any Web page encoded by UTF-8, whether in Chinese, Japanese, Korean, or Arabic, can be displayed correctly, UTF-8 is the world's universal language encoding, UTF-8 's promotion is thanks to Google Apps and blog developers. If you use Windows XP English version of IE6.0 to browse for a gb2312 language-encoded Web page, you will be prompted to install the language pack. As a result, many foreign viewers may be lost.

The advantage of using the GB2312 encoding is that the page text generated by the program uses the ANSI encoding format, which saves a bit more volume than the UTF-8 text encoding, and the access speed is a little faster, and the volume ratio is greater than the exact experiment I'm doing here.

We take a look at the Japanese language blog, the use of Japanese (EUC) encoding, UTF-8 encoding is the majority of the Korean language blog,utf-8 encoding Majority, Korean (EUC), Korean also accounted for a large part.

From this, it can be concluded that the use of UTF-8 language encoding, or the use of national language coding, and whether there is no relationship between patriotism, or, at all, there is no relationship, in China, no one is unpatriotic. I have been wandering between UTF-8 and gb2312, do you want to use UTF-8 encoding? Million to ask.



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.