Hello,
$url = 'http://www.domain.com/file.php?dir=r&hl=100,200&ord=3&key=a+b+c';
If it were a url I could get value of hl
by, say, $_GET['hl']
. but how do I retrieve the same from $url string.
Thanks.
Hello,
$url = 'http://www.domain.com/file.php?dir=r&hl=100,200&ord=3&key=a+b+c';
If it were a url I could get value of hl
by, say, $_GET['hl']
. but how do I retrieve the same from $url string.
Thanks.
Here are the steps:
$url = 'http://www.domain.com/file.php?dir=r&hl=100,200&ord=3&key=a+b+c';
print "<pre>";
print $url;
$url_parsed = parse_url($url);
print_r($url_parsed);
parse_str($url_parsed['query'], $url_parts);
print_r($url_parts);
print "</pre>";
Produces this output:
http://www.domain.com/file.php?dir=r&hl=100,200&ord=3&key=a+b+cArray
(
[scheme] => http
[host] => www.domain.com
[path] => /file.php
[query] => dir=r&hl=100,200&ord=3&key=a+b+c
)
Array
(
[dir] => r
[hl] => 100,200
[ord] => 3
[key] => a b c
)
See parse_url()
and parse_str()
So the steps to get the h1
value you want are:
$url = 'http://www.domain.com/file.php?dir=r&hl=100,200&ord=3&key=a+b+c';
$url_parsed = parse_url($url);
parse_str($url_parsed['query'], $url_parts);
print $url_parts['h1'];