url decode problem 解决方法

yipeiwu_com6年前PHP代码库
试验了一下python的urllib库以及js 的 encodeURIComponent 均不会替换。空格encode也是替换成了 '%20' 。python提供了urllib.quote_plus, urlib.unquote_plus来处理空格->加号,看起来还是比较合理的。

查了一下 RFC 3986: 有下面一段

Scheme names consist of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus ("+"), period ("."), or hyphen ("-").
RFC 2396 有下面的一段

The plus "+", dollar "$", and comma "," characters have been added to those in the "reserved" set, since they are treated as reserved within the query component.
表示加号已经是url的保留字了,不需要转义。

然后html4文档里才有关于加号的转义:

application/x-www-form-urlencoded
Forms submitted with this content type must be encoded as follows:
Control names and values are escaped. Space characters are replaced by`+', and then reserved characters.....
声明只有content-type为application/x-www-form-urlencoded时才会对+做转义。

又翻了下php的文档,发现有一个

rawurlencode() - URL-encode according to RFC 3986


也就是php又搞了rawurlencode和rawurldecode把标准实现了。。。。

不能反一下么,毕竟大部分人应该都会用urlencode。php真是蛋疼啊。。。。

相关文章

php获取开始与结束日期之间所有日期的方法

本文实例讲述了php获取开始与结束日期之间所有日期的方法。分享给大家供大家参考,具体如下: /** * 获取指定日期段内每一天的日期 * @param Date $startda...

百度工程师讲PHP函数的实现原理及性能分析(一)

百度工程师讲PHP函数的实现原理及性能分析(一)

前言 在任何语言中,函数都是最基本的组成单元。对于php的函数,它具有哪些特点?函数调用是怎么实现的?php函数的性能如何,有什么使用建议?本文将从原理出发进行分析结合实际的性能测试尝试...

基于php实现的验证码小程序

基于php实现的验证码小程序

验证码功能(个人理解): 减轻服务器的压力(如12306的验证码功能); 防止暴力注册 个人思路:在a-z,A-Z,1-9生成n位随机的数来构成新的验证码。 关于生成验证码的...

PHP排序算法的复习和总结

直接上代码吧! 复制代码 代码如下: <?php /* * 插入排序(一维数组) * 每次将一个待排序的数据元素,插入到前面已经排好序的数列中的适当的位置,使数列依然有序;直到待排...

PHP 伪静态隐藏传递参数名的四种方法

伪静态方法一: 复制代码 代码如下: <?php //伪静态方法一 // localhost/php100/test.php?id|1@action|2 $Php2Html_Fil...