使用 &在 URL 错误了 $_GET [英] Using & in URL bugs up the $_GET

查看:43
本文介绍了使用 &在 URL 错误了 $_GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 http://validator.w3.org/check 运行我的网站,我得到了很多错误消息说我的链接应该使用 & 而不是 &.

Running my site through http://validator.w3.org/check, I get a lot of error messages saying that my links should use & in stead of &.

所以我更新了我的代码,结果发现$_GET 不喜欢这个.

So I updated my code, only to find out that $_GET does not like this.

我的网址是这样的:www.mysite.com/?foo=1&bar=2
我把它改成这样:www.mysite.com/?foo=1&bar=2

问题是做一个 print_r($_REQUEST) 给了我这个结果:

The problem is that doing a print_r($_REQUEST) gives me this result:

Array ( [foo] => 1 [amp;storeid] => 2 ) 

为什么 $_GET$_POST$_REQUEST 不能识别 & ?

Why doesn't $_GET, $_POST and $_REQUEST recognize the & ?

更新
这是我生成 URL 的方法之一:

UPDATE
This is one of the ways I generate a URL:

$url = get_bloginfo('url')."/?foo=".$element['name']."&bar=".$element['id'];
$link = '<a href="'.$url.'" title="'.$element['name'].'">'.$element['name'].'</a>';

推荐答案

&amp;& 的 HTML 实体参考.URL 参数仍然由单个 & 分隔,但是如果您在 HTML 中提及 URL,则需要对其进行编码.对于

&amp; is the HTML entity reference for &. URL parameters are still separated by a single &, but if you mention the URL in HTML, you need to encode it. For

<img src="img?width=100&amp;height=100" />

浏览器然后请求 img?width=100&height=100.

这篇关于使用 &amp;amp;在 URL 错误了 $_GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆