Easiest is to use the regx
preg_match("/^(http:\/\/)?([^\/]+)/i", preg_replace( "#^[^:/.]*[:/]+#i", "", preg_replace( "{/$}", "", urldecode($resource_url))), $domain_data);
$website_domain_only = strtolower(preg_replace('#^www\.(.+\.)#i', '$1', $domain_data[2]));
echo $website_domain_only;
OR
You can also use the builtin method which is slow. Wrapped it as a function below.
echo url_to_domain($your_url_here);
function url_to_domain($url)
{
$host = @parse_url($url, PHP_URL_HOST);
if (!$host)
$host = $url;
if (substr($host, 0, 4) == "www.")
$host = substr($host, 4);
return $host;
}