parse_url - get the domain name from url
by rajesh[ Edit ] 2010-01-02 18:09:30
parse_url - Parse a URL and return its components.
If we want the domain name or protocol or arguments from the url, we can just simply use parse url function in php.
Parse_url takes url as argument and returns
* scheme - e.g. http
* host
* port
* user
* pass
* path
* query - after the question mark ?
* fragment - after the hashmark #
Example Code:
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
?>
The above example will output:
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)