Instead of encoding the space, Google uses the same q
variable to accomplish the same thing.
Unfortunately, PHP doesn't have the built-in ability to do this, because successive occurrences of the same query string parameter will overwrite the first one, unless the []
suffix is used.
You would need something like this:
$params = array();
foreach (explode('&', $_SERVER['QUERY_STRING']) as $param) {
list($name, $value) = explode('=', $param, 2);
$params[] = array(urldecode($name) => urldecode($value));
}
Contents of $params
:
array(
array('q' => 'site:phpjs.org'),
array('q' => 'date'),
);
Alternatively, you can change the loop body to this:
$params[urldecode($name)][] = urldecode($value);
That will change $params
to:
array('q' => array('site:phpjs.org', 'date'));
Which will make it easier to just do:
join(' ', $params['q']);
// "site:phpjs.org date"