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 set_time_limit()函数的使用详解

语法 : void set_time_limit (int seconds)说明 : 设定一个程式所允许执行的秒数,如果到达限制的时间,程式将会传回错误。它预设的限制时间是30秒,max...

mac系统下安装多个php并自由切换的方法详解

前言 最近工作中遇到一个问题,需要实现在mac系统下安装多个php并实现自由切换,通过查找相关的资料找到了解决的方法,所以想着总结下来,方便大家和自己学习参考,下面话不多说,来看看的介绍...

php使用timthumb生成缩略图的方法

本文实例讲述了php使用timthumb生成缩略图的方法。分享给大家供大家参考,具体如下: 生成缩列图有二种方式: 一、提前生成好,供调用 缩列图常规做法是,开始根据网站中的图片规格,要...

php在多维数组中根据键名快速查询其父键以及父键值的代码

我这么想的: 遍历一遍多维数组,将所有的键建立索引生成一个一维数组; 每次通过键名去查这个键的上级数组及数据 OK,代码如下 indexKey创建索引数组函数: 复制代码 代码如下: &...

PHP编程实现脚本异步执行的方法

本文实例讲述了PHP编程实现脚本异步执行的方法。分享给大家供大家参考,具体如下: php语言得用fsockopen()函数,实现脚本异步运行,代码如下 异步请求函数(用debug参数若为...