Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在url中安全地传递参数_Php_Cakephp_Cakephp 1.3_Urlencode_Url Encoding - Fatal编程技术网

Php 如何在url中安全地传递参数

Php 如何在url中安全地传递参数,php,cakephp,cakephp-1.3,urlencode,url-encoding,Php,Cakephp,Cakephp 1.3,Urlencode,Url Encoding,我正在使用像这样的URL参数 http://localhost/articles/?author=Ben%20Cooper%2CAlex%20Hunter&title=.....&tags=.. 我在链接中对它们进行URL编码。在参数中有特殊字符之前,所有这些都有效 比如说 http://localhost/articles/?author=..&title=&tags=.. 如果,在标题“我有爱与生活”中,它第一次编码时有爱+%26+生活,有时会变成Love

我正在使用像这样的URL参数

http://localhost/articles/?author=Ben%20Cooper%2CAlex%20Hunter&title=.....&tags=..
我在链接中对它们进行URL编码。在参数中有特殊字符之前,所有这些都有效

比如说

http://localhost/articles/?author=..&title=&tags=..
如果,在标题“我有爱与生活”中,它第一次编码时有爱+%26+生活,有时会变成
Love+%26amp%3B+生活。

为什么会这样?非常感谢您的帮助。

您需要先使用。这将改变
&
(为html而不是URL编码)转换成
&
,然后
取消编码()
,这将把它转换成
%26


HTML和URL具有不同的保留字符,编码方式也不同。许多框架将自动编码html实体,以帮助防止页面呈现异常。想象一下,在后一种情况下,在URL编码之前,它是XML/HTML编码的(尽管
(空格)
+
的转换超出了百分比编码的定义):它是
爱情与生活
->
爱情与爱情;生活就是这样。但是因为我既不使用PHP也不使用Cake。。。不能再多说了:)至于html实体的确切编码位置,或者为什么它有时编码,而不是其他编码,我不能帮助不实际查看您的代码。
$str = 'Love & Life'; //start with string that may or may not contain htmlentities
$decodedStr = html_entity_decode($str); //replace html entities with their literal counterparts
$urlEncodedStr = urlencode($decodedStr); //urlencode!