根据链接地址获取域名
程序员文章站
2024-02-19 18:45:16
...
// 根据链接地址获取域名
public static function getRootDomain($url) {
$ohurl = $ohip = array ();
$url = $url . "/";
preg_match ( "/((\w*):\/\/)?\w*\.?([\w|-]*\.(com.cn|net.cn|gov.cn|org.cn|com|net|cn|org|asia|tel|mobi|me|tv|biz|cc|name|info))\//i", $url, $ohurl );
if (! isset ( $ohurl [3] ) || $ohurl [3] == '') {
preg_match ( "/((\d+\.){3}\d+)\//", $url, $ohip );
return isset ( $ohip [1] ) ? $ohip [1] : '';
}
return $ohurl [3];
}
推荐阅读