Differences between rawurlencode () and urlencode () Functions

Source: Internet
Author: User

This article introduces the differences between rawurlencode () and urlencode () functions. For more information, see.

 

Today, when I read the open source code, I found a URL encoding function: rawurlencode (), which has never been noticed before, because urlencode () is used in normal development (), therefore, I made some special research.

In fact, the difference between the two functions is very simple. Both of them will escape non-English characters in the URL and replace it with "%" followed by two hexadecimal numbers. The difference is: rawurlencode complies with RFC 1738, a 94-year international standard memorandum, and the escape for spaces is '% 20'. The urlencode encoding implements the traditional approach, like the data in the POST form, spaces are converted to "+.

For example:
If the URL source is in the form of: http://www.bKjia. c0m encoding difference
Rawurlencode ($ url ):
Http % 3A % 2F % 2Fityizhan.com % 2 FPHP % 20% E7 % BC % 96% E7 % A0 % 81% E5 % 8C % BA % E5 % 88% AB % 2B
Urlencode ($ url ):
Http % 3A % 2F % 2Fityizhan.com % 2 FPHP + % E7 % BC % 96% E7 % A0 % 81% E5 % 8C % BA % E5 % 88% AB % 2B

The difference between the two is obvious from this example. If we want to decode the encoded URL, we can use the two functions: rawurldecode () and urldecode (). In actual development, we recommend that you use rawurlencode () for URL encoding to avoid inconsistent URL formats.

The same operation has some differences in Javascript. For details, refer to: URL encoding and anti-encoding in javascript, which describes escape (), encodeURI (), encodeURIComponent () in Javascript () encoding usage

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.