Escape,encodeuri,encodeuricomponent

Source: Internet
Author: User

Javascript/js, there are three functions that can encode strings, namely: escape,encodeuri,encodeuricomponent, corresponding 3 decoding functions: Unescape,decodeuri, decodeURIComponent .

Escape () function

Definition and Usage: the Escape () function encodes the string so that it can be read on all computers.

Syntax: Escape (String)

Parameter description: String required. The string to be escaped or encoded.

Return value: A copy of the encoded string. Some of these characters are replaced with 16-binary escape sequences.

Description: 1. The method does not encode ASCII letters and numbers, nor does it encode the following ASCII punctuation marks:-_. ! ~ * ' ()

2.escape does not encode 69 characters: *,+,-,.,/,@,_,0-9,a-z,a-z.

3. All other characters will be replaced by escape sequences.

4. It is rarely used and is not recommended to encode this way

encodeURI () function

Definition and Usage: the encodeURI () function encodes a string as a URI.

Syntax: encodeURI (uristring)

Parameter description: uristring required. A string that contains the URI or other text to encode.

Return value: A copy of uristring, where some of the characters will be replaced by a hexadecimal escape sequence.

Description: The method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks:-_. ! ~ * ' ().

The purpose of this method is to fully encode the URI, so the encodeURI () function is not escaped for the following ASCII punctuation mark with a special meaning in the URI:;/?:@&=+$,#

encodeURI does not encode 82 characters:!,#,$,&, ', (,), *,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,a-z

encodeURIComponent () function

Definition and Usage: the encodeURIComponent () function encodes a string as a URI component.

Syntax: encodeURIComponent (uristring)

Parameter description: uristring required. A string that contains the URI component or other text to encode.

Return value: A copy of uristring, where some of the characters will be replaced by a hexadecimal escape sequence.

Description: The method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks:-_. ! ~ * ' ().

Other characters (such as:;/?:@&=+$,# These punctuation marks used to separate the URI component) are replaced by one or more hexadecimal escape sequences.

encodeURIComponent does not encode 71 characters:!, ', (,), *,-,.,_,~,0-9,a-z,a-z

Note: Escape outputs%u**** format when encoding Unicode values other than 0-255, and escape,encodeuri,encodeuricomponent encoding results are the same in other cases

Tip: Note the difference between the encodeURIComponent () function and the encodeURI () function, which assumes that its arguments are part of a URI (such as a protocol, hostname, path, or query string).

Therefore, the encodeURIComponent () function escapes punctuation marks that are used to separate portions of the URI.

These three functions, Escape () escape encoding all incoming strings in addition to ASCII letters, numbers, and specific symbols, so it is best not to use this method if you want to encode the URL.

                      encodeuri () is used to encode the entire URI because the legitimate characters in the URI are not converted by encoding.

The encodeURIComponent method encodes a single uricomponent (the request parameter) should be the most common, it can be described in the parameters of Chinese, special characters escaped, without affecting the entire URL.

The most commonly used should be encodeuricomponent, which is to convert the Chinese, Korean and other special characters into the utf-8 format of the URL encoding, So if you need to use encodeURIComponent to pass parameters to the background, you need the background decoding to Utf-8 support (the encoding in form is the same as the current page encoding method)

GBK: full name is the code extension specification for Chinese characters, English name Chinese Internal Code specification, is the expansion of GB2312, still use two bytes to represent Chinese characters. Using double-byte representation, the overall encoding range is 8140-fefe, the first byte between 81-fe, the tail byte between the 40-FE, culling xx7f a line. A total of 23,940 code positions, a total income of 21,886 Chinese characters and graphic symbols, including Chinese characters (including radicals and components) 21,003, graphic symbols 883.

UTF-8: (8-bit Unicode Transformation Format) is a variable-length character encoding for Unicode, also known as the Universal Code. UTF-8 encodes Unicode characters in 1 to 6 bytes. The same page can be used to display Chinese simplified traditional and other languages (such as English, Japanese, Korean).

UTF-8 and GBK, characters are represented by double-byte, except that the highest bit is set to 1 for distinguishing Chinese. As for the UTF-8 encoding, which is used to solve the international character of a multibyte encoding, it uses 8 bits (that is, one byte) in English, the Chinese use 24 bits (three bytes) to encode. For forums with more English characters, you can save space with UTF-8. The GBK contains all the Chinese characters, and UTF-8 contains all the symbols that are needed in all countries of the world. GBK is in the national standard GB2312 based on the expansion of compatible GB2312 standards (as if not national standards) UTF-8 encoded text can be displayed in various countries support UTF8 character set browser. For example, if it is a UTF8 code, it can display Chinese in the foreigner's English ie, without requiring them to download IE's Chinese language support package. Therefore, for the more English forum, use GBK each character occupies 2 bytes, and the use of UTF-8 English is only a single byte. UTF8 is an international code, its versatility is better, foreigners can also browse the forum, GBK is the country code, the commonality is worse than UTF8, but UTF8 occupies a larger database than GBK.

Cond!
Characters are represented by double-byte, except that the highest bit is set to 1 for distinguishing Chinese. As for the UTF-8 encoding, which is used to solve the international character of a multibyte encoding, it uses 8 bits (that is, one byte) in English, the Chinese use 24 bits (three bytes) to encode. For forums with more English characters, you can save space with UTF-8. The GBK contains all the Chinese characters, and UTF-8 contains all the symbols that are needed in all countries of the world. GBK is in the national standard GB2312 based on the expansion of compatible GB2312 standards (as if not national standards) UTF-8 encoded text can be displayed in various countries support UTF8 character set browser. For example, if it is a UTF8 code, it can display Chinese in the foreigner's English ie, without requiring them to download IE's Chinese language support package. Therefore, for the more English forum, use GBK each character occupies 2 bytes, and the use of UTF-8 English is only a single byte. UTF8 is an international code, its versatility is good, foreigners can also browse the forum, GBK is the country code, the commonality is worse than UTF8, but the UTF8 occupies the database than the GBK large characters are used double-byte to represent, only to distinguish the Chinese, the highest bit of it is set to 1.
As for the UTF-8 encoding, which is used to solve the international character of a multibyte encoding, it uses 8 bits (that is, one byte) in English, the Chinese use 24 bits (three bytes) to encode. For forums with more English characters, you can save space with UTF-8.
The GBK contains all the Chinese characters, and UTF-8 contains all the symbols that are needed in all countries of the world.
GBK is in the national standard GB2312 based on the expansion of compatible GB2312 standards (as if not national standards) UTF-8 encoded text can be displayed in various countries support UTF8 character set browser. For example, if it is a UTF8 code, it can display Chinese in the foreigner's English ie, without requiring them to download IE's Chinese language support package. Therefore, for the more English forum, use GBK each character occupies 2 bytes, and the use of UTF-8 English is only a single byte.
UTF8 is an international code, its versatility is better, foreigners can also browse the forum, GBK is the country code, the commonality is worse than UTF8, but UTF8 occupies a larger database than GBK UTF-8 (8-bit Unicode transformation Format) is a variable-length character encoding for Unicode, also known as the Universal Code. UTF-8 encodes Unicode characters in 1 to 6 bytes. The same page can be used to display Chinese simplified traditional and other languages (such as English, Japanese, Korean).

UTF-8 (8-bit Unicode Transformation Format) is a variable-length character encoding for Unicode, also known as the Universal Code. UTF-8 (8-bit Unicode Transformation Format) is a variable-length character encoding for Unicode, also known as the Universal Code. UTF-8 (8-bit Unicode Transformation Format) is a variable-length character encoding for Unicode, also known as the Universal Code. UTF-8 (8-bit Unicode Transformation Format) is a variable-length character encoding for Unicode, also known as the Universal Code. UTF-8 (8-bit Unicode Transformation Format) is a variable-length character encoding for Unicode, also known as the Universal Code. UTF-8 (8-bit Unicode Transformation Format) is a variable-length character encoding for Unicode, also known as the Universal Code.

Escape,encodeuri,encodeuricomponent

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.