Detailed explanation of language encoding of charset in html

黄舟
Release: 2017-07-22 13:31:51
Original
3084 people have browsed it

Pay attention to the importance of HTML language encoding

  • Directory


  1. ##Importance of charset encoding

  2. Where is charset in html

  3. charset tag

  4. Encoding type

  5. charset utf-8 introduction

  6. Introduction to charset GB2312

  7. Recommended web page encoding

  8. Web page compatibility due to encoding

1. The importance of encoding -

TOP

Encoding can cause garbled web pages when viewers use IE, and can also cause p+css compatibility Hack.

2. Encoding position -

TOP

3. HTML encoding style -

TOP
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Copy after login

By changing The utf-8 in charset=utf-8 can change the encoding of the web page.
Generally when we write a CSS file, we also need to use
@charset "utf-8"; at the top of the CSS file to define the encoding type of this CSS file. Generally, the HTML source code and CSS file encoding must be unified. If they are not unified, it will lead to compatibility issues such as CSS hacks, garbled pages, and chaotic page layout.

4. Commonly used html encoding types -

TOP

The two popular ones commonly used in China are utf-8 and gb2312. Generally, these two types can meet domestic web page encoding needs. Of course, these two encoding types are also used in programs and databases to process web pages and store data types.

5. UTF-8 has the following characteristics: -

TOP

    ##UCS characters U+0000 to U+007F (ASCII) are encoded as Bytes 0x00 to 0x7F (ASCII compatible). This means that files containing only 7-bit ASCII characters are the same in both ASCII and UTF-8 encodings.
  1. All> The UCS character ;U+007F is encoded as a string of multiple bytes, each with a set of flag bits. Therefore, the ASCII bytes (0x00-0x7F) cannot be part of any other character.
  2. The first byte of a multi-byte string representing a non-ASCII character is always in the range 0xC0 to 0xFD, and indicates how many bytes this character contains. The rest of the multi-byte string Bytes are all in the range 0x80 to 0xBF. This makes resynchronization very easy, and makes the encoding borderless and rarely affected by missing bytes.
  3. Can encode all possible The 231 UCS codes
  4. UTF-8 encoded characters can theoretically be up to 6 bytes long, but 16-bit BMP characters can only be up to 3 bytes long.
  5. Bigendian UCS-4 byte strings are arranged in a predetermined order.
  6. Bytes 0xFE and 0xFF are never used in UTF-8 encoding .
  7. 6. GB2312 has the following characteristics -
TOP

GB2312 standard contains a total of 6763 Chinese characters, including 3755 first-level Chinese characters and second-level Chinese characters. There are 3008 Chinese characters; at the same time, GB2312 includes 682 full-width characters including Latin letters, Greek letters, Japanese hiragana and katakana letters, and Russian Cyrillic letters.

The emergence of GB2312 basically meets the computer processing needs of Chinese characters. The Chinese characters it contains have covered 99.75% of the frequency of use. In GB2312, the collected Chinese characters are "partitioned", and each zone contains 94 Chinese characters/symbols. This representation is also called location code.

01-09 area contains special symbols.

Areas 16-55 are first-level Chinese characters, sorted by pinyin.

Areas 56-87 are second-level Chinese characters, sorted by radical/stroke.

Districts 10-15 and 88-94 are not coded.

For example, the character "ah" is the first Chinese character in GB2312, and its location code is 1601. In programs using GB2312, the byte structure usually uses the EUC storage method so that Compatible with ASCII. Each Chinese character and symbol is represented by two bytes. The first byte is called the "high byte" and the second byte is called the "low byte". The "high byte" uses 0xA1-0xF7 (add 0xA0 to the area code of area 01-87), and the "low byte" uses 0xA1-0xFE (add 01-94 to 0xA0). For example The word "ah" is stored as 0xB0A1 in most programs. (Compare with location code: 0xB0=0xA0+16, 0xA1=0xA0+1).

So the decimal system of the Chinese character area code in GB2312 encoding is from 176 to 247, and the bit code is from 161 to 255. The reason why the stored 6763 is less than 82*94=6768 is because the area code is 215, and the bit code is from 161 to 255. There are five codes between 250 and 254 without Chinese character coding, so 6768-5=6763.

GB2312 encoding can be understood as a common language in China.

7. Recommended charset encoding -

TOP

##UTF-8 can be easily understood. Simplified and Traditional Chinese can use this encoding. For example, Taiwan and Mainland China use this encoding. .

8. Web page compatibility errors caused by encoding: - TOP

#If the encoding is mixed, the web page will be garbled, which is also called incompatible, especially if encoding mixing is used in CSS comments row will result in css hack.

I hope you will never forget to declare the web page encoding when making web pages in the future.

Users who have viewed this page have also viewed the following content:
1. The differences and relationships between UTF-8 GBK UTF8 GB2312
2. How to choose html encoding
3. html encoding settings

The above is the detailed content of Detailed explanation of language encoding of charset in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template