Web page coding that's the thing.

Source: Internet
Author: User

Coding has always been a headache for the novice, especially GBK, GB2312, UTF-8 the three more common differences in the page encoding, but also let many novice disoriented, how to explain the explanation is not clear. But coding is so important, especially in this piece of Web page. If you call out is not garbled, and the Web page garbled, most of the reasons are on the code. In addition to garbled, there will be some other problems (such as: IE6 CSS loading problem) and so on. The Stalker M writes the purpose of this article, is to thoroughly explain this coding problem! If you're having a similar problem, take a closer look at this post.

ANSI, GBK, GB2312, UTF-8, GB18030, and UNICODE

These few coding keywords are more common, although I put us together to say, but does not mean that these things are a lateral relationship. This part of the content, quoted from the network slightly modified, do not know the source of the original, it can not be signed.

A long time ago, a group of people decided to use 8 transistors that could be opened and closed to form different states to represent everything in the world, which they called "bytes". Later, they did some of the machines that can handle these bytes, the machine started, can use bytes to assemble a lot of states, the state began to change, they called the machine "computer."

Start computer is only used in the United States. A total of eight bytes can be combined with 256 (2 of 8) different states. They have a number from 0 to start the 32 states have specified a special purpose, but the terminal, the printer when the agreed-upon these bytes are transmitted, it is necessary to do some of the agreed action. Meet 00x10, terminal on line, meet 0x07, terminal on people toot called, example Good met 0x1b, printer on the print anti-white word, or terminal on the color display letters. They see this very well, so they call these 0x20 byte states as "control codes".

They also put all the spaces, punctuation, numbers, uppercase and lowercase letters with a continuous byte state, has been compiled into the 127th, so that the computer can use different bytes to store English text. You see this, all feel good, so everyone put this program is called ANSI "Ascii" code (American Standard Code for Information interchange, U.S. Information Interchange Standard code). All the computers in the world used the same ASCII scheme to save English text.

Later, the computer development more and more widely, the world countries in order to be able to save their text in the computer, they decided to use the vacancy after 127th to express these new letters, symbols, but also added a lot of drawing tables need to use the bottom line, vertical line, cross and other shapes, has been numbered into the last state 255. The character set of this page from 128 to 255 is called "Extended character set". But the original numbering method, has no longer put more coding.

When the Chinese people get the computer, there is no available byte state to represent Chinese characters, and there are more than 6,000 commonly used Chinese characters need to be preserved. So the Chinese people on their own research and development, those 127th after the strange symbols are directly canceled off. Rule: A character less than 127 is the same as the original, but two more than 127 words connect prompt together, it represents a Chinese character, the preceding byte (which he calls a high byte) is used from 0xa1 to 0xf7, followed by a byte (low byte) from 0xa1 to 0xFE, This allows us to assemble about 7,000 + Simplified Chinese characters. In these codes, we also put mathematical symbols, Roman Greek alphabet, Japanese kana have been compiled into, even in ASCII, the number, punctuation, letters are all re-compiled two bytes long code, this is often said "full-width" character, and the original under 127th is called "Half-width" character.

The Chinese people see this is very good, so they call this scheme "Gb2312″." GB2312 is a Chinese extension to ASCII .

But Chinese characters too many, and later still not enough to use, so simply no longer require that the low byte must be 127th after the inner code, as long as the first byte is greater than 127 fixed indicates that this is the beginning of a Chinese character, whether followed by the expansion of the character set in the content. The result of the expanded coding scheme is called the GBK Standard, and GBK includes all the contents of the GB2312, while adding nearly 20,000 new Chinese characters (including traditional characters) and symbols. Later, the minority also to use the computer, so we expanded, and added thousands of new minority characters,GBK expanded into a GB18030. Since then, the Chinese nation's culture can be passed on in the computer age.

Because at that time each country like China to make a set of their own coding standards, the results of each other who do not know who the code, who does not support the code of others. At that time, the Chinese want to let the computer display Chinese characters, it must be loaded with a "Chinese character system", specifically to deal with the display of Chinese characters, input problems, installed the wrong character system, display will be messy set. What about this? At this point, an international organization called ISO (International Standard organization) decided to tackle the problem. Their approach is simple: to scrap all the regional coding schemes and to re-engage a code that includes all the cultures, letters and symbols on Earth! They intend to call it "Universal multiple-octet Coded Character Set", referred to as UCS, commonly known as "UNICODE".

When UNICODE began to develop, the memory capacity of the computer developed greatly, and space no longer became a problem. The ISO then directly stipulates that all characters must be represented uniformly by two bytes, or 16 bits, and for those "half-width" characters in ASCII, the UNICODE package holds its original encoding unchanged, only extending its length from the original 8 bits to 16 bits, while the characters of other cultures and languages are all re-encoded. Since the "Half-width" English symbol only needs to use the low 8 bits, so its high 8 bits is always 0, so this atmosphere of the scheme in the preservation of English text will be more than a waste of space.

However, Unicode is not designed to be compatible with any of the existing encoding schemes, which makes GBK and UNICODE completely different in the coding of Chinese characters, and there is no simple arithmetic method to convert text content from UNICODE encoding to another encoding. This conversion must be done by looking up a table. UNICODE is represented as a character in two bytes, and he can combine 65535 different characters in total, which may already cover all the cultural symbols of the world.

When Unicode comes along with the advent of computer networks, how Unicode is transmitted over the network is also a must-have issue, so many UTF (UCS Transfer Format) standards for transmission appear, as the name implies,UTF8 That is, each time 8 bits of data transmission, and UTF16 is 16 bits each time, but in order to transmit the reliability, from Unicode to UTF is not a direct correspondence, but to pass some algorithms and rules to convert.

After reading these, I believe that you have a few coding relationships, and so on, know more clearly. Let me summarize briefly:

1, the Chinese people through the expansion of the ASCII encoding of Chinese, produced a GB2312 code, can represent more than 6,000 commonly used Chinese characters.

2, Chinese characters are too many, including traditional and various characters, so produced a GBK code, which includes the GB2312 in the code, while expanding a lot.

3, China is a multi-ethnic country, almost all nationalities have their own independent language system, in order to represent those characters, continue to expand the GBK code to GB18030 encoding.

4, each country like China, the language of their own code, so there are a variety of codes, if you do not install the corresponding code, you can not explain the corresponding code to express the content.

5, finally, there is an organization called ISO can not look down. Together they create a coded UNICODE that is large enough to accommodate any word or symbol in the world. So as long as the computer has Unicode encoding system, no matter what kind of text in the world, only need to save the file, save the Unicode encoding can be normal interpretation by other computers.
UNICODE in the network transmission, there are two standard UTF-8 and UTF-16, each transmitting 8 bits and 16 bits.

So there will be some doubts, UTF-8 since can save so many words, symbols, why there are so many people using GBK and other code? Because UTF-8 and other coding volume is relatively large, accounting for more computer space, if the use of the majority of people are Chinese, using GBK and other codes can also. But the current computer, hard disk is the price of cabbage, computer performance has been enough to ignore this performance of the consumption. So recommend all the Web pages using the Unified code:UTF-8.

Web page coding that's the thing.

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.