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

Ken Moore psm2713 at hotmail.com
Sat Dec 6 14:21:46 CST 2003


Hi Dunston,

Dunstan Orchard wrote

>Hi there,
>
>This is a tricky one I think.
>
>I have a collection of URLs, for example:
>
>http://story.news.yahoo.com/news/
>http://www.amazon.com/exec/obidos/ASIN/B0000C0FKA/
>http://www.metafilter.com/mefi/28945
>http://www.s-curverecords.com/joss/
>http://www.tenaciousd.com/
>
>I need to get only the main domain names from this list, eg:
>
>yahoo.com
>amazon.com
>metafilter.com
>s-curverecords.com
>tenaciousd.com

Not so tricky at all. Assuming that there are a set number of top-level 
domains (com, gov, net) and that there is a set number of characters (".", I 
think is the only one) that begin the TL name, do a string processing 
routine that looks for the "." and the TL domain such as "com". Take those 
four characters and all of the ones back to the ".".

That should do it.

Ken - Who wouldnot string you along.

_________________________________________________________________
Cell phone ‘switch’ rules are taking effect — find out more here. 
http://special.msn.com/msnbc/consumeradvocate.armx



More information about the thelist mailing list