Turning a query string into an array after using parse_url Okay, I am afraid this might be a 'duh!' question, but I am just having one of those days!   Well, the problem is, I am getting the following error every time I have a query string in my url (https://www.google.com/?q=hello):

Recoverable fatal error: Argument 1 passed to drupal_http_build_query() must be an array, string given

I am modifying a custom module that someone else wrote and this is the code that is problematic.  

$pieces = parse_url($href);
$pieces['html'] = TRUE;
$pieces['path'] = isset($pieces['path']) ? $pieces['path'] : '';
if (isset($pieces['scheme'])) {
  $pieces['path'] = $pieces['scheme'] . '://' . $pieces['host'] . $pieces['path'];
}

return l($image, $pieces['path'], $pieces);


This is what $pieces looks like:

scheme (String, 5 characters ) https
host (String, 13 characters ) www.google.com
path (String, 22 characters ) https://www.google.com/
query (String, 6 characters ) q=hello
html (Boolean) TRUE


Obviously, the problem is due to $query not being an array.  I am wondering how best to rewrite the above code so that I can properly call the l() function with the query string and any other attributes that a user might put in there.  Any and all help would be greatly appreciated.  Thanks.
You need to use an associative array, e.g.

$pieces['query'] = array('q' =&gt; 'hello');


The arguments for l() are in no way related to, or compatible with, the return from parse_url(). To avoid confusion it'd be better to build up a separate options array to pass as the 3rd argument to l().