You're looking for the function parse_url().
$url ='http://www.whatever.com/path/to/some/directory/';
extract(parse_url($url));
Now you have a variable $host which has the value 'www.whatever.com', as well as a couple others you may be interested in, too: $scheme, $port, $user, $pass, $path, $query, and $fragment.