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