Home >Web Front-end >HTML Tutorial >What are the language encodings of HTML?

What are the language encodings of HTML?

php中世界最好的语言
php中世界最好的语言Original
2017-11-23 16:10:324119browse

In HTML, encoding can cause the webpage to be garbled when the viewer passes IE, and can also cause compatibility Hack of div+css. Encoding is very important. Generally, the encoding position is placed in the <head of the HTML page. >Between . Today we will introduce some knowledge about coding.

Generally, this webpage encoding is placed between and in the html webpage.

htmlEncoding style

Pass Changing the utf-8 in charset=utf-8 can change the encoding of the web page.

Generally when we write CSS files, 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.

Commonly used HTML encoding types

The two most 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.

UTF-8 has the following properties

UCS characters U+0000 to U+007F (ASCII) are encoded as bytes 0x00 to 0x7F (ASCII compatible). This means that only 7 bits are included ASCII character files are the same in both ASCII and UTF-8 encoding methods.

All >U+007F UCS characters are encoded as a multi-byte string, each byte There is a set of flag bits. Therefore, ASCII bytes (0x00-0x7F) cannot be part of any other character.

The first byte of a multi-byte string representing a non-ASCII character is always between 0xC0 and is in the range 0xFD, and indicates how many bytes this character contains. The remaining bytes of a multibyte string are in the range 0x80 to 0xBF. This makes resynchronization very easy, and makes the encoding borderless and less susceptible to missing words. The impact of sections.

Can encode all possible 231 UCS codes

UTF-8 encoded characters can theoretically be up to 6 bytes long, however 16-bit BMP characters can only be to 3 bytes long.

The arrangement order of Bigendian UCS-4 byte strings is predetermined.

Bytes 0xFE and 0xFF are never used in UTF-8 encoding.

GB2312 has the following characteristics

GB2312 standard contains a total of 6763 Chinese characters, including 3755 first-level Chinese characters and 3008 second-level Chinese characters; at the same time, GB2312 includes Latin letters, Greek letters, and Japanese hiragana. and 682 full-width characters including 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 to be 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" will be 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.

Recommended charset encoding

UTF-8 can be easily understood. Simplified and Traditional Chinese can use this encoding, such as Taiwan and Mainland China.

Web page compatibility errors caused by encoding

If the encoding is mixed, the web page will be garbled, which is also called incompatible, especially in CSSCommentsIf the encoding is mixed, it will be Causes css hack.

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

The above is the knowledge of HTML language encoding. For more exciting information, please pay attention to php Chinese website Other related articles!

Related content:

How to know what CSS property style to set for DIV?

Why do we need to set CSS styles on DIV?

How to use the

tag of html

The above is the detailed content of What are the language encodings of HTML?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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