|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 )
PetePumaHow many lumps do you wantPremium,MVM
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.
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.