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实现观察者模式(Observer)

学习php设计模式 php实现观察者模式(Observer)

一、意图 定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新【GOF95】 又称为发布-订阅(Publish-Subscribe)模式...

PHP实现恶意DDOS攻击避免带宽占用问题方法

使用PHP代码实现的DDOS攻击会导致带宽被占用,变成卡B。 处理办法是: 修改php.ini文件 1) "disable_functions"改成gzinflate,默认是放空 2)...

深入分析php中接口与抽象类的区别

接口和抽象类真的很难区分开,引文他们很相似,方法都没有定义逻辑,都是供子类是想或继承的。区分二者只要记住一句话:接口是规范,类是实现。接口的目的是定义一个规范,大家都遵守这个规范。也就是...

PHP递归复制、移动目录的自定义函数分享

虽然复制一个目录是文件操作的基本功能。但PHP中也没有给出特定的函数,同样需要自定义一个递归函数实现。要复制一个包含多个子目录的目录,将涉及文件的复制、目录创建等操作。复制一个文件可以通...

数据库中排序的对比及使用条件详解

假定MySQL服务器和PHP服务器都已经按照最适合的方式来配置,那么系统的可伸缩性(Scalability)和用户感知性能(User-perceived Performance)是我们追...