抓取Refferer的URL - PHP

I am trying to grab statistics on my site and I need a way in PHP to assign just the referrer URL to a variable. All I want is just the "www" or subdomain, the domain, and the tld... I.E. www.facebook.com instead of http://www.facebook.com/BLAH-BLAH/?blah=blah

Try something like the following:

$referer = $_SERVER['HTTP_REFERER'];
$parts = parse_url($referer);
echo $parts['host']; //should echo example.com, or whatever
<?php
$ref = $_SERVER["HTTP_REFERER"];
$host = null;
if ($ref != null) {
  $parse = parse_url($ref);
  $host = $parse["host"];
}
?>

and then you have $host to work with