dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
7
share rss forum feed

vollie

join:2009-01-15

1 edit
reply to Jafo232

Re: PHP: Get TLD from URL

ok, so i was looking for a straight-out answer to your question, then figured it out myself, and figured i might as well post it...
So, without further ado:

(?:.+://)?(?:[^/]*\.)?([^/]+\.[^/]+)(?:/?.*)?
replaced by $1

will strip anything other then the bla.bla before the / in any url, reliable as hell.

Oh, since you're using php; don't forget the starting and ending thing so like:
preg_replace('@(?:.+://)?(?:[^/]*\.)?([^/]+\.[^/]+)(?:/?.*)?@', '$1', $url);

(PS. if you do happen to find some way to beat it, please inform me )
--
Chris Volwerk
»boe-end.nl/



PetePuma
How many lumps do you want
Premium,MVM
join:2002-06-13
Arlington, VA

This might not work for .co.uk URLs, where you want the last *3* parts of the URL. The country domains are a tricky bunch, and are not consistent.


vollie

join:2009-01-15

Mh, forgot about that one, thanks. Luckily I needed the subdomain as well (whereby (?:.+://)?([^/]+)(?:/?.*)? does the trick), but in this case it seems one needs to stick with JAAulde's answer indeed.
--
Chris Volwerk
»boe-end.nl/