The difference analysis of JS character coding function

Source: Internet
Author: User

Http://www.jb51.net/article/14657.htm JS has 3 functions for text encoding: escape,encodeuri,encodeuricomponent, corresponding decoding function: Unescape, Decodeuri,decodeuricomponent  1, escape to encode characters other than ANSI code 0-255 output%u**** format is the Unicode value, the Escape method returns a string value (in Unicode format) that contains the contents of the charstring. All spaces, punctuation, accent marks, and other non-ASCII characters are replaced with%XX encoding, where xx equals the hexadecimal number that represents the character. For example, a space returns "%20"
Escape does not encode characters with 69: *,+,-,.,/,@,_,0-9,a-z,a-z

2. encodeURI similar to escape for address bar coding
encodeURI does not encode 82 characters:!,#,$,&, ', (,), *,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,a-z

3, encodeURIComponent for address bar coding. Encodes a text string as a valid component of a Uniform Resource Identifier (URI). It is the Chinese, Korean and other special characters into the utf-8 format of the URL encoding, if your page encoding is gb2312, the server side will be garbled.
encodeURIComponent does not encode 71 characters:!, ', (,), *,-,.,_,~,0-9,a-z,a-z

So JS using the data can use escape, for the address bar data, it is best to use encodeuricomponent encoding.do not understand the function can be searched!

The difference analysis of JS character coding function

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.