url decode problem 解决方法

yipeiwu_com5年前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 /** * PHP 年龄计算函数 * * 参数支持数组传参和标准的 Mysql date 类型传参 * params sample * -----...

PHP迭代与递归实现无限级分类

PHP迭代与递归实现无限级分类

无限级分类是开发中常见的情况,因此本文对常见的无限极分类算法进行总结归纳. 1.循环迭代实现 $arr = [ 1=>['id'=>1,'name'=>'父1'...

基于preg_match_all采集后数据处理的一点心得笔记(编码转换和正则匹配)

1、使用curl实现站外采集 具体请参考我上一篇笔记:https://www.jb51.net/article/46432.htm 2、编码转换首先通过查看源代码找到采集的网站使用的编码...

php中使用PHPExcel读写excel(xls)文件的方法

本文实例讲述了PHP中使用PHPExcel读写excel(xls)文件的方法,非常实用。分享给大家供大家参考之用。具体方法如下: 很多PHP类库在读取中文的xls、csv文件时会有问题,...

使用URL传输SESSION信息

使用URL传输SESSION信息

 在php的学习中,会话是我们常常用到的,那今天我们就来详细讲讲会话中的session; 一、session的工作机制: 当开启session后,服务器会在服务器中保存sess...