note 95304 added to function.parse-url

From: Date: Fri, 25 Dec 2009 13:57:02 +0000
Subject: note 95304 added to function.parse-url
Groups: php.notes 
Request: Send a blank email to php-notes+get-164322@lists.php.net to get a copy of this message
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']); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 64.255.180.84 (proxied: 58.147.169.103) ---- Manual Page -- http://www.php.net/manual/en/function.parse-url.php Edit -- https://master.php.net/note/edit/95304 Del: integrated -- https://master.php.net/note/delete/95304/integrated Del: useless -- https://master.php.net/note/delete/95304/useless Del: bad code -- https://master.php.net/note/delete/95304/bad+code Del: spam -- https://master.php.net/note/delete/95304/spam Del: non-english -- https://master.php.net/note/delete/95304/non-english Del: in docs -- https://master.php.net/note/delete/95304/in+docs Del: other reasons-- https://master.php.net/note/delete/95304 Reject -- https://master.php.net/note/reject/95304 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164322) next »