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 global $PHP_SELF; //echo $PHP_SELF; $t1=$_POST['textfield1']; $t2=$_POST[...

php中实现可以返回多个值的函数实例

本文实例讲述了php中实现可以返回多个值的函数用法。分享给大家供大家参考。具体分析如下: 在python和golang中都有一个函数同时返回多个值的方法,其实php也可以,但相比pyth...

PHP 加密解密内部算法

将它们打包成一个文件就叫fun.php吧 复制代码 代码如下: <?php function passport_encrypt($txt, $key) { srand((doubl...

理解PHP5中static和const关键字的区别

PHP5中加入了很多面向对象的思想,PHP5的面向对象比较接近Java的面向对象思想。我们这里对PHP5中的static和const关键字作用进行一下描述,希望对学习PHP5的朋友有帮助...

PHP中VC6、VC9、TS、NTS版本的区别与用法详解

1. VC6与VC9的区别: VC6版本是使用Visual Studio 6编译器编译的,如果你的PHP是用Apache来架设的,那你就选择VC6版本。 VC9版本是使用Visual S...