An in depth analysis of PHP rawurlencode and urlencode functions

  • 2020-06-12 08:37:11
  • OfStack

Problem: Both functions escape strings to make them suitable filenames. Which one should I use? Which is more standard?

Conclusion:
rawurlencode complies with the 1994 International Standards Memorandum RFC 1738,
urlencode implements the traditional approach, with the main difference being that the escape of whitespace is '+' rather than '%20'
The encodeURL of javascript is also the 94 standard,

escape of javascript is another way to mark unicode encoding with "%xxx".

rawurlencode is recommended for PHP. Deprecated urlencode

The sample
source:

Superhuman sadha sajdh data sample sdls ES31en.file.jpeg

PHP urlencode:
%E8%B6%85%E7%BA%A7%E6%97%A0%E6%95%8C%E7%9A%84%E4%BA%BAsadha+sajdh%E6%95%B0%E6%8D%AE%E6%A0%B7%E6%9C%ACsdls+fhejrthcxzb.file.jpeg

PHP rawurlencode:
%E8%B6%85%E7%BA%A7%E6%97%A0%E6%95%8C%E7%9A%84%E4%BA%BAsadha%20sajdh%E6%95%B0%E6%8D%AE%E6%A0%B7%E6%9C%ACsdls%20fhejrthcxzb.file.jpeg

Javascript encodeURI:
%E8%B6%85%E7%BA%A7%E6%97%A0%E6%95%8C%E7%9A%84%E4%BA%BAsadha%20sajdh%E6%95%B0%E6%8D%AE%E6%A0%B7%E6%9C%ACsdls%20fhejrthcxzb.file.jpeg

Javascript escape:
%u8D85%u7EA7%u65E0%u654C%u7684%u4EBAsadha%20sajdh%u6570%u636E%u6837%u672Csdls%20fhejrthcxzb.file.jpeg


Related articles: