URL Multiple Query Parameters Encoded with HTML Entities

I came across a situation where a URL with multiple query parameters was encoded using htmlentities() and PHP was not recognizing the query parameters using $_GET. A common case for encoding urls using htmlentities() is to use them inside XML documents.

So a url with multiple query parameters, encoded using htmlentities() would look like this:

http://www.bradino.com/?color=white&size=medium&quantity=3

and when that url is accessed the second and third query parameters are not recognized because instead of separating the subsequent variables with an & that character gets converted into &. I could not find a good way to resolve this, so basically I just encoded the query string back to normal using html_entity_decode() and then slammed the parameters back into the $_GET array using parse_str().

$query = html_entity_decode($_SERVER['QUERY_STRING']);
 
parse_str($query,$_GET);

There must be a better way! Anyone come across this before?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>