Is it possible to get a first-level domain name code for each type of URL?
This post was last edited by Changjay on 2010-09-07 23:25:30
There are many URLs, like abc.abc.com, Abc.com/abc, www.abc.com.cn, abc.com.tw, www.abc.co.uk, WWW.ABC.COM.JP/ABC.PHP/ID=ABC (id= It can be long after ABC)
There are a lot of things that I hope can be omnipotent.
How do I get the first-level domain name for all URLs in PHP? Get results for abc.com,abc.com.cn, abc.co.uk?
The situation is more complicated. I use the following code, roughly can be judged, but when the domain name has Com,net,org,gov,cc,biz,info,cn,co, the result is a problem.
Www.cool.com, for example, became www.co.
Hope that the regular master to help me to modify, become a universal domain name code.
$url = $row ["url"];
Preg_match ("#[\w-]+\." ( Com|net|org|gov|cc|biz|info|cn|co) (\. ( Cn|hk|uk)) *# ", $url, $match);
echo $match [0];
------Solution--------------------
$s = <<< TEXT
Abc.abc.com
Abc.com/abc
www.abc.com.cn
abc.com.tw
www.abc.co.uk
Www.abc.com.jp/abc.php/id=abc
Www.cool.com
TEXT;
foreach (Split ("[\r\n]+", $s) as $url) {
Preg_match ("#[\w-]+\." ( Com
------Solution--------------------
Net
------Solution--------------------
Org
------Solution--------------------
Gov
------Solution--------------------
Cc
------Solution--------------------
Biz
------Solution--------------------
Info
------Solution--------------------
cn
------Solution--------------------
CO) \b (\. ( cn
------Solution--------------------
hk
------Solution--------------------
uk
------Solution--------------------
Jp
------Solution--------------------
TW)) *# ", $url, $match);
echo "
" . $match [0];
}
Abc.abc.com
ABC.com
Abc.com/abc
ABC.com
www.abc.com.cn
abc.com.cn
abc.com.tw
abc.com.tw
www.abc.co.uk
abc.co.uk
Www.abc.com.jp/abc.php/id=abc
abc.com.jp
Www.cool.com
Cool.com