process a url query string in PHP

PHP Function to parse a url and extract its arguments.

  
  
function process_url( $url ) {
    $processed_url = parse_url( $url );
    $query_string = ;
    # split into arguments and values
    $query_string = explode( '&', $processed_url[ 'query' ]);
    $args = array( ); // return array
    foreach( $query_string as $chunk ) {
        $chunk = explode('=', $chunk );
        # it's only really worth keeping if the parameter has an argument.
        if ( count( $chunk ) == 2 ) {
            list( $key, $val ) = $chunk;
            $args[ $key ] = urldecode( $val );
        }
    }
    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 );

print_r( $result );

Will result in something like this:

  
Array 
(
    [q] => simon rocks!
    [start] => 0  
    [ie] => utf-8
    [oe] => utf-8
    [client] => firefox-a
    [rls] => org.mozilla:en-US:official
)