view raw
zuk1 zuk1 - 10 months ago 97
PHP Question

Parsing Domain From URL In PHP

I need to build a function which parses the domain from a URL.

So, with


it should return


it should return


Check out parse_url():

$url = '';
$parse = parse_url($url);
print $parse['host']; // prints ''

parse_url doesn't handle really badly mangled urls very well, but is fine if you generally expect decent urls.