Get the subdomain from a URL
Posted
by jb
on Stack Overflow
See other posts from Stack Overflow
or by jb
Published on 2008-11-13T23:54:05Z
Indexed on
2010/04/03
20:13 UTC
Read the original article
Hit count: 191
Getting the subdomain from a URL sounds easy at first.
http://www.domain.example
Scan for the first period then return whatever came after the "http://" ...
Then you remember
http://super.duper.domain.example
Oh. So then you think, okay, find the last period, go back a word and get everything before!
Then you remember
http://super.duper.domain.co.uk
And you're back to square one. Anyone have any great ideas besides storing a list of all TLDs?
John
© Stack Overflow or respective owner