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通过function_exists检测函数是否存在的方法

本文实例讲述了php通过function_exists检测函数是否存在的方法。分享给大家供大家参考。具体分析如下: php中可以通过function_exists()函数检测另外一个函数...

PHP后期静态绑定实例浅析

本文实例讲述了PHP后期静态绑定。分享给大家供大家参考,具体如下: 从php5.3开始,php增加了一个叫后期绑定的功能,用于在继承范围内引用静态调用的类 该功能从语言内部角度考虑北命名...

php采集内容中带有图片地址的远程图片并保存的方法

本文实例讲述了php采集内容中带有图片地址的远程图片并保存的方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下:function my_file_get_contents...

PHP调试函数和日志记录函数分享

网站程序开发过程经常需要调试,发布阶段也需要记录运行日志,方便发现问题和还原事件。这就要求有调试和日志记录功能。 下面分别写了用于调试的函数和用于记录错误的函数。 使用方法很简单,且自动...