PHP 用正则获取URL的根域名

function GetUrlRoot($url)
{
preg_match('/[w][w-]*.(?:com.cn|com|cn|co|net|org|gov|cc|biz|info)(/|$)/isU', $url, $domain);
return rtrim($domain[0], '/');
}

原文地址:https://www.cnblogs.com/chenjian/p/4184108.html