Home > php教程 > php手册 > PHP rawurlencode与urlencode函数的深入分析

PHP rawurlencode与urlencode函数的深入分析

WBOY
Release: 2016-06-06 20:31:21
Original
1370 people have browsed it

本篇文章是对PHP中的rawurlencode与urlencode函数进行了详细的分析介绍,需要的朋友参考下

问题:2个函数都是针对字符串转义使其适合做文件名。该用哪个?哪个更标准?

结论:
rawurlencode遵守是94年国际标准备忘录RFC 1738,香港服务器租用,
urlencode实现的是传统做法,和上者的主要区别是对空格的转义是'+'而不是'%20'
javascript的encodeURL也是94年标准,美国空间,

而javascript的escape是另一种用"%xxx"标记unicode编码的方法。

推荐在PHP中使用用rawurlencode。弃用urlencode

样例
source:

超级无敌的人sadha sajdh数据样本sdls fhejrthcxzb.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 labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template