function getDomain($url){
$rs = parse_url($url);
if(!isset($rs['host'])) return null;
$main_url = $rs['host'];
if(!strcmp(long2ip(sprintf('%u', ip2long($main_url))), $main_url)) {
return $main_url;
} else {
$arr = explode('.', $main_url);
$count = count($arr);
$endArr = array('com', 'net', 'org'); //com.cn net.cn 等情况
if (in_array($arr[$count - 2], $endArr)){
$domain = $arr[$count - 3] . '.' . $arr[$count - 2] . '.' . $arr[$count - 1];
} else {
$domain = $arr[$count - 2] . '.' . $arr[$count - 1];
}
return $domain;
}
}