If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
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.htmAnyway,
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:





