note 120899 deleted from function.parse-url by cmb
| From: | cmb@php.net | Date: | Sun, 08 Sep 2019 10:35:02 +0000 |
| Subject: | note 120899 deleted from function.parse-url by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212155@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
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']);
?>https://vb.3dlat.net/