Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using & in URL bugs up the $_GET

Tags:

url

php

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 &.

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

My URL was this: www.mysite.com/?foo=1&bar=2
and I changed it to this: www.mysite.com/?foo=1&bar=2

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

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

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

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>';
like image 474
Steven Avatar asked Jun 12 '11 14:06

Steven


1 Answers

&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" />

the browser then requests img?width=100&height=100.

like image 127
phihag Avatar answered Sep 26 '22 15:09

phihag