Sizetrac

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?

  • Digg
  • TwitThis
  • del.icio.us
  • Netvouz
  • description
  • Reddit
  • Furl
  • NewsVine
  • Simpy
  • Slashdot
  • Spurl
  • StumbleUpon
  • YahooMyWeb
  • TailRank
  • Technorati
  • Facebook
  • Google
  • LinkedIn
  • Live
  • MySpace
  • Ping.fm
  • Yahoo! Buzz
  • E-mail this story to a friend!



Home | PHP | URL Multiple Query Parameters Encoded with HTML Entities