note 75944 rejected from function.http-parse-params by mike
| From: | mike@php.net | Date: | Thu, 28 Jun 2007 17:35:01 +0000 |
| Subject: | note 75944 rejected from function.http-parse-params by mike | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-128058@lists.php.net to get a copy of this message | ||
Note Submitter: Siegfried Gevatter rainct at ubuntuwire dot com
----
<?PHP
/* This simple function gets the query out of a URL, splits it
* and puts it into an array.
*
* For example, "index.php?name=Myself&message=Hello" will
* become an array looking like this:
* array['name'] = 'Myself'
* array['message'] = 'Hello'
*/
function getParser($url) {
// Extract the query
$query = parse_url($url);
$query = $query['query'];
// Split it
$query = explode('&', $query);
// Get the elements and put them in an array
$gets = array();
foreach($query AS $element) {
list($name, $value) = explode('=', $element, 2);
$gets[$name] = $value;
}
// Return the array
return $gets;
}
// Example
$_GET = getParser($_SERVER['REQUEST_URI']);
// Let's look what it got
echo '<pre>';
print_r($_GET);
echo '</pre>';
?>