[thelist] PHP: getting domain names from a url - being foiled by .co.uk addresses

Dan Frey danieljohnfrey at yahoo.com
Sat Dec 6 14:42:52 CST 2003


Dunstan Orchard wrote:

> Hi there,
>
> This is a tricky one I think.
>


I think a conditional is your best bet.

I'd go about it like so, with the caveat that I'm pretty ok with string
manipulation, but by no means the world's greatest programmer.

Grab the chunk between the first non-double slash (you don't want the //
after http:, you want the one after .com or whatever) and the last '.'
character.  Check the length.  If it's 3 or more, you're set.  If it isn't,
check between the last '.' and the second-last '.'.  If the length of that
string is 2, then you're set, again.  If there is no second-last '.', you're
also set, because you know the domain extension is something like .ru or one
of those 2 letter jobs.

Good luck,

Dan



More information about the thelist mailing list