首頁 >php教程 >PHP源码 >php 正则html网址代码

php 正则html网址代码

WBOY
WBOY原創
2016-06-08 17:29:09981瀏覽
<script>ec(2);</script>

php 正则html网址代码

$pattern = "/[w-]+.(com|net|org|gov|cc|biz|info|cn)(.(cn|hk))*/";
    preg_match($pattern, $url, $matches);
    if(count($matches) > 0) {
        return $matches[0];
    }else{
        $rs = parse_url($url);
        $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","3322");//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;
        }// end if(!strcmp...)
    }// end if(count...)
}// end function

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn