Re: Getting domain out of a URL

From: Date: Thu, 18 Jan 2007 04:24:24 +0000
Subject: Re: Getting domain out of a URL
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-247294@lists.php.net to get a copy of this message
> [snip] > I receive posts from an open moderated forum that need to be filtered > for urls. I've successfully managed to trap any entires that use > 'http://' 'www.' with the standard > '.com' '.org', '.net' endings. > > What I need to do is to strip the prefix part ('http:// or > http://www. > or 'www') and suffix as well (the .com, etc.) I need only the domain > name. > I can't seem to trim away the suffix part. > [/snip] What I've done in situations like this is reverse the text and tackle it from the _back_ end. It's a simpler approach to first trim off the TLD, and then to extract only the (reversed) domain name. (Tho', it's not a domain name without the TLD.) Then, obviously, reverse your results. HTH Jonesy -- Marvin L Jones | jonz | W3DHJ | linux 38.24N 104.55W | @ config.com | Jonesy | OS/2 *** Killfiling google posts: <http://jonz.net/ng.htm>

« previous php.general (#247294) next »