Parse a URL in PHP to return domain

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

RJ

Domain BuyerTop Member
Impact
3,218
Please write a short php function to parse a URL and return just the domain name.

Example:
Code:
$url="http://www.namepros.com/showthread.php?p=350493";

$domain = getdomain($url); # domain equals "namepros.com"

Offering a new domain registration.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
You blokes are a riot :O

Now that was a lively thread! Good to see that it didn't get too personal :cy:

Say, what would have to be added to these scripts if one wanted to pull out just the domain name itself, separate from the TLD? For instance,

Code:
[B][SIZE=3][COLOR=Indigo]http://www.domain_name.com
             and I want to pull out "domain_name"[/COLOR][/SIZE][/B]

Is this possible, to just get that domain name alone? I would think it is, but my head is not filled with nearly enough knowledge like some of the guru's here. I did read some stuff on the "explode();" function, but it's all a bit beyond me.

Thanks for the time on this. Looking forward to getting a response.

James.
 
0
•••
Bump...

Bump

Anybody?

Thanks.
 
0
•••
All you'd have to do is use the working function they have above. Once you do that you can use explode or split I perfer split for some reason. But just put this line in somewhere:
list($domain, $extention) = split('[.]', $fulldomain);

I believe you have to have the . in square brackets or do something special but I forget right now and I don't have time to test it out.
 
0
•••
Cool, Thanks

Cool. Thanks for the direction. I'll give it a shot later today when I have some time as well. If I get it to do what I'd like, I'll be sure to post what I get back up here.

Thanks again.

JDK.
 
0
•••
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com
Catchy
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back