PHP:
-
// Function to parse a url and extract its arguments.
-
function process_url( $url )
-
{
-
-
$query_string = $processed_url[ 'query' ];
-
-
# split into arguments and values
-
-
-
foreach( $query_string as $chunk )
-
{
-
// it's only really worth keeping if the parameter
-
// has an argument.
-
{
-
}
-
}
-
-
return $args;
-
}
-
-
$url = 'http://www.google.co.nz/search?q=simon+rocks!&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US:official';
-
-
$result = process_url( $url );
-
Will result in something like this:
PHP:
-
(
-
[q] => simon rocks!
-
[start] => 0
-
[ie] => utf-8
-
[oe] => utf-8
-
[client] => firefox-a
-
[rls] => org.mozilla:en-US:official
-
)
Thanks! Saved me weeks!
Why not just use parse_str()?
Michael, that's a very good question! I seem to recall writing this to get around a limitation of parse_str(), but looking at the code today, I cannot work out what that would be!
--Simon