Jump to content

PHP: Parse url into array


Recommended Posts

  • Administrators

I'll like to thank Jan Suomi for finding this one:


Its a neat little php script for parsing a URL and splitting into a array:


function parse_query($var) {
* Use this function to parse out the query array element from
* the output of parse_url().
$var = parse_url($var, PHP_URL_QUERY);
$var = html_entity_decode($var);
$var = explode('&', $var);
$arr = array();

foreach($var as $val) {
$x = explode('=', $val);
$arr[$x[0]] = $x[1];
unset($val, $x, $var);
return $arr;
$url = "http://somefunny.url.com/click?z=26&a=761";

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...