Check out parse_url()
:
$url = 'http://google.com/dhasjkdas/sadsdds/sdda/sdads.html';
$parse = parse_url($url);
echo $parse['host']; // prints 'google.com'
parse_url
doesn't handle really badly mangled urls very well, but is fine if you generally expect decent urls.