• read.
    The Prince by Niccolo Machiavelli
  • read.
    The Count of Monte Cristo by Alexandre Dumas
  • read.
    Invisible Man by Ralph Ellison

Php: how to get base domain

The problem: take a url (in this case, we’ll specify an absolute url,
http and all) and return only the base domain. For instance, given
www.domain.com’ or ’sub.subdomain.domain.com’, it should return
‘domain.com’.

Simple
enough, but now consider: ‘http://www.example_site.com.pk’ or
http://damnlimies.co.uk’ or
‘http://username:password@this.is.a.worst.shortly.subdomain.thisIsMyMainWebsite.com.cl

It is an anvil upon which many a hammer has been broken:

http://lists.evolt.org/archive/Week-of-Mon-20031201/152316.html
http://www.webmasterworld.com/forum88/10656.htm

Anyway,
I think I have a solution. I won’t bother with the details of how I
arrived at it. Suffice to say, you just need to break down your own url
parsing process. It passed the battery of tests at the end:

Phosphorus and Lime: PHP: Get Base Domain