Extract domain from url (including the hard ones)
Posted
by karl
on Stack Overflow
See other posts from Stack Overflow
or by karl
Published on 2010-03-26T22:39:37Z
Indexed on
2010/03/26
22:43 UTC
Read the original article
Hit count: 193
I'm trying to write (or just find an existing) PHP method that can take a link and extract the url. The trick is, it needs to hold under the weight of strange looking domains like:
www.champa.kku.ac.th
Looking at this one myself with human eyes, I still guessed it incorrectly: thought the domain would be kku.ac.th
but that gives a dns error when visiting.
So anyone knows of a good way to reliably extract the domain from url:
http://site.com/hello.php
http://site.com.uk/hello.php
http://subdomain.site.com/hello.php
http://subdomain.site.com.uk/hello.php
http://www.champa.kku.ac.th/hello.php // and even the one I couldn't tell
© Stack Overflow or respective owner