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后期静态绑定之self::限制实例分析

本文实例讲述了PHP后期静态绑定之self::限制。分享给大家供大家参考,具体如下: 在此我想讲一讲后期静态绑,我想讲self::与static进行比较说明。 官方文档上是这样定义的:...

php中利用post传递字符串重定向的实现代码

复制代码 代码如下: $ch = curl_init('http://domain-name.com/page.php');       curl_seto...

微信公众平台开发教程①获取用户Openid及个人信息图文详解

微信公众平台开发教程①获取用户Openid及个人信息图文详解

本文实例讲述了微信公众平台开发获取用户Openid及个人信息。分享给大家供大家参考,具体如下: 前言: 初次尝试微信公众号的开发,对于学习方法的探索都是来源于网上的博客、问答,对于参差...

PHP不使用内置函数实现字符串转整型的方法示例

PHP不使用内置函数实现字符串转整型的方法示例

介绍 php字符串类型的数字如果想转成整型的数字,一般我们都是采用系统内置的API去做转换,但如果规定就不让我们去用系统内置的API转换,而是让自己去实现一个函数转换该怎么办?这里我们看...

php文件下载处理方法分析

本文实例讲述了php文件下载的处理方法。分享给大家供大家参考。具体分析如下: php能够处理多种条件的文件下载,先来看下面示例: <?php header("Conte...