The following code can get the domain name from the URL
Example: http://bkjia.com/live/q.html
Get bkjia.com
The following is the referenced content: function Get_domain ($url) { $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, etc. 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 |
http://www.bkjia.com/PHPjc/363986.html www.bkjia.com true http://www.bkjia.com/PHPjc/363986.html techarticle The following code can get the domain name from the URL for example: http://liehuo.net/live/q.html get liehuo.net The following: function Get_domain ($url) {$pattern =/[\ W-]+\. (com|net|org ...