ConFoo Montreal 2026: Call for Papers

Voting

: max(four, zero)?
(Example: nine)

The Note You're Voting On

need_sunny at yahoo dot com
15 years ago
Thanks to xellisx for his parse_query function. I used it in one of my projects and it works well. But it has an error. I fixed the error and improved it a little bit. Here is my version of it:

<?php
// Originally written by xellisx
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;
}
?>

At the first line there was parse_query($val), I made it $var. It used to return a null array before this fix.

I have added the parse_url line. So now the function will only focus in the query part, not the whole URL. This is useful if something like below is done:
<?php
$my_GET
= parse_query($_SERVER['REQUEST_URI']);
?>

<< Back to user notes page

To Top