Get url parameters from url-string

Lets say, we have an url as variable. We want to parse its each parameters.
Here is a solution:

$url = 'https://www.google.co.uk/search?hl=en&tbo=d&site=&source=hp&q=skin+smoothing+cream&hl=en&ei=YqVnUu2BCYfZrQfRwYFw&start=10&sa=N';

$urlParam = parse_url($url);
print_r($urlParam);
/*
Array
(
    ['scheme'] => https
    ['host']   => www.google.co.uk
    ['path']   => /search
    ['query']  => hl=en&tbo=d&site=&source=hp&q=skin+smoothing+cream&hl=en&ei=YqVnUu2BCYfZrQfRwYFw&start=10&sa=N
)
*/

parse_str($urlParam['query'], $queryParam);
print_r($queryParam);
/*
Array
(
    ['hl']      => en
    ['tbo']     => d
    ['site']    => 
    ['source']  => hp
    ['q']       => skin smoothing cream
    ['ei']      => YqVnUu2BCYfZrQfRwYFw
    ['start']   => 10
    ['sa']      => N
)
*/
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s