How to choose the correct understanding and use GBK and UTF-8 web code _ HTML/Xhtml _ web page Production

Source: Internet
Author: User
Web page encoding is to specify its specific character encoding format library in the web page, this article will introduce GBK and UTF-8 web page encoding definition and application web page encoding, is a library that specifies its specific character encoding format on a webpage.
GBK is compatible with GB2312 after expansion based on the National Standard GB2312. The GBK text encoding is expressed in double bytes, that is, both Chinese and English characters are expressed in Double Bytes. To distinguish Chinese characters, set the highest bit to 1. GBK contains all Chinese characters. It is a national code and has poor universality than UTF8. However, the database occupied by UTF8 is larger than that occupied by GBK.

UTF-8: Unicode TransformationFormat-8bit that allows BOM inclusion, but typically does not. It is a multi-byte encoding for international characters. It uses 8 bits (one byte) for English and 24 bits (three bytes) for Chinese characters. UTF-8 contains all the characters needed by all countries in the world, is an international code, universal. UTF-8-encoded text can be displayed on browsers that support UTF8 character sets in countries. If it is UTF-8 encoded, Chinese characters can be displayed on Internet Explorer of foreigners. They do not need to download the Chinese language support package for Internet Explorer.
Although the UTF-8 version has good international compatibility, but Chinese needs more than GBK/BIG5 version occupies 50% of the database storage space, so it is not recommended to use, it is only applicable to users who have special requirements on international compatibility. Simply put: for websites with a large number of Chinese characters, it is suitable to use GBK encoding to save database space. For more English websites, suitable for the use of UTF-8 to save database space.

How do I convert GBK, GB2312, and UTF8? GBK, GB2312, and so on must be encoded with Unicode to convert each other: GBK, GB2312 -- Unicode -- UTF8; UTF8 -- Unicode -- GBK, GB2312. Using the Save As in Windows notepad, you can convert between GBK, Unicode, Unicode big endian, and UTF-8 encoding methods.

How can the browser correctly identify the webpage code? Generally, the following sentence is required on the webpage: Indicates that the character set encoding of this webpage is GB2312. (Or UTF-8)
Why does a page sometimes contain garbled characters when encoding is specified? This may be because the encoding of the page declaration is inconsistent with the encoding of the file itself. More often, it is caused by opening the page with an error code and saving it. Or, you can directly modify the file online using some FTP software, such as CuteFTP, the code is incorrectly converted due to software encoding configuration errors. In this case, use the notepad of window and save it as the corresponding encoding to solve the problem.

When using IE as a browser in a windows operating system, this problem often occurs: When browsing a Web page that uses UTF-8 encoding, the browser cannot automatically identify the encoding used by the page, even if the webpage has already declared the encoding format: , Which causes some pages containing Chinese UTF-8 encoding to generate a blank output. If you are using Firefox or Sarafi browsers, this will not cause this problem. This is because IE gives priority to HTML tags when parsing webpage code, and then the messages in HTTP headers, whereas mozilla browsers are just the opposite.

Because the UTF-8 is 3 bytes to indicate a man, while the ordinary GB2312 or BIG5 is two. When the page is output, the browser parses and outputs IfThere are an odd number of full-width characters in front, IE treats the UTF-8 as two bytes when parsing half Chinese characters, then the half Chinese characters willOf <结合成一个乱码字,导致ie无法读完 To make the entire page empty, and if you look at the source file at this time, you will find that the entire page has actually been output, but the browser does not display the content. The simplest solution is <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">Put in <title>Before.

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.