Re[2]: [PHP] Parse domain from URL

From: Date: Wed, 06 Jun 2007 16:20:46 +0000
Subject: Re[2]: [PHP] Parse domain from URL
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-256198@lists.php.net to get a copy of this message
Hi Brad, Wednesday, June 6, 2007, 5:04:41 PM, you wrote: > Yes, that's basically what my code already does. > The problem is that what if the url is > "http://yahoo.co.uk/" (note the lack > of a subdomain) > Your script thinks that the domain is "co.uk". Just like my existing code > does. > So we can't count on taking the last 2 segments. And we can't count on > ignoring the first segment. (The subdomain could be anything, not just www) The complete list of top-level domains is neither very long, nor changes very often. Perhaps a new country/suffix now and again is added or renamed, but it doesn't happen that much. In short, I think it'd be much better for you to obtain a full list and then just remove that element from your hostname. Then you'll know for a fact that whatever is left is the pure domain (+ sub-domain). Of course it won't help if someone gives you the IP of a site (or any other similar variation) instead of a domain name :) Cheers, Rich -- Zend Certified Engineer http://www.corephp.co.uk "Never trust a computer you can't throw out of a window"

« previous php.general (#256198) next »