dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
7
share rss forum feed


Jafo232
You Can't Spell Democrat Without Rat.
Premium
join:2002-10-17
Boonville, NY
reply to JAAulde

Re: PHP: Get TLD from URL

said by JAAulde:

Code and output: »codepad.org/LSQ1VyyL

Edit: this could be done with a regex, but URLs can vary so widely that I'd rather take a few steps and use built in functions where possible. I think this is more reliable in this case.
I tried that code and the output was:

"com"
--
Custom PHP/Perl Development. Vbulletin And Wordpress Mods Too!


JAAulde
Web Developer
Premium,MVM
join:2001-05-09
Williamsport, MD
kudos:3

1 recommendation

said by Jafo232:

said by JAAulde:

Code and output: »codepad.org/LSQ1VyyL

Edit: this could be done with a regex, but URLs can vary so widely that I'd rather take a few steps and use built in functions where possible. I think this is more reliable in this case.
I tried that code and the output was:

"com"
Which would be the TLD


Jafo232
You Can't Spell Democrat Without Rat.
Premium
join:2002-10-17
Boonville, NY

1 edit
reply to Jafo232
Actually your code is right, what I asked for is wrong. I need the domain name with the TLD, example:

http://www.dslreports.com/some/path/to/a/file.ext?name=value
 

To return just:

dslreports.com

Same with any URL:

http://somesubdomain.domain.com/path/to/somewhere
 

--
Custom PHP/Perl Development. Vbulletin And Wordpress Mods Too!


JAAulde
Web Developer
Premium,MVM
join:2001-05-09
Williamsport, MD
kudos:3

1 edit

1 recommendation

Ahh, I see. Very well then:

»codepad.org/UXGS161q

If both TLD and "top level host" are found, you should get them back. Otherwise you get an empty string.


Jafo232
You Can't Spell Democrat Without Rat.
Premium
join:2002-10-17
Boonville, NY
Thanks JAAulde! I will try this out. Hopefully it will work better than some of the other code I have tinkered with.
--
Custom PHP/Perl Development. Vbulletin And Wordpress Mods Too!


Jafo232
You Can't Spell Democrat Without Rat.
Premium
join:2002-10-17
Boonville, NY
reply to JAAulde
JAAulde, shot your a private message..