Jump to content

PHP: Parse url into array


Leon

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:

 


<?php
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";
print_r(parse_query($url));
?>

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...