php 正则html网址代码
$pattern = "/[w-] .(com|net|org|gov|cc|biz|info|cn)(.(cn|hk))*/";
preg_match($pattern, $url, $matches);
if(count($matches) > 0) {
返回$matches[0];
}其他{
$rs = parse_url($url);
$main_url = $rs["主机"];
if(!strcmp(long2ip(sprintf("%u",ip2long($main_url))),$main_url)) {
返回 $main_url;
}其他{
$arr = Explode(".",$main_url);
$count=count($arr);
$endArr = array("com","net","org","3322");//com.cn net.cn 等情况
if (in_array($arr[$count-2],$endArr)){
$domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1];
}其他{
$domain = $arr[$count-2].".".$arr[$count-1];
}
返回 $domain;
}// 结束 if(!strcmp...)
}// 结束 if(count...)