It is not feasible to get the first level domain name code of each kind of URL

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.