$dom = "2.dd.com.cn";
$dom = "2.dd.net.cn";
$dom = "2.dd.cn";
$dom = "2.dd.com";
$dom = "http://finance.qq.com/a/20091126/005836.htm";


echo get_top_dom($dom);

function get_top_dom($dom)
{
 $gendom_arr = array( "com.cn" , "net.cn" , "org.cn" , "co.jp" , "co.kr" , "com.hk" , "com.tw" );
 $dom =  str_replace("http://","",$dom);
 $dom =  str_replace("ftp://","",$dom);
 $dom = preg_replace( "#/.*#i" , "" , $dom);
 $arr = explode(".",$dom);
 $len = count($arr);
 if($len>2)
 {
  $topdom = $arr[$len-2]. "." . $arr[$len-1];
  if(in_array($topdom,$gendom_arr))
  {
   $topdom = $arr[$len-3]. "." . $topdom;
  }
  return $topdom;
 }
 else
 {
     return $dom;
 }
}

Posted on 2009-11-26 17:15  古代  阅读(282)  评论(0编辑  收藏  举报