URL Multiple Query Parameters Encoded with HTML Entities
Like this blog? Consider exploring one of our sponsored banner ads...
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:
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?
About this entry
You’re currently reading “URL Multiple Query Parameters Encoded with HTML Entities,” an entry on BRADINO
- 9.11.09 / 5pm