Getting domain from URL
Moderator: General Moderators
- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
Getting domain from URL
Just wanting to get just the real domain (not subdomains) out of a URL. Or from another place if there is one. But like, have a webmail login form, and want users to input just their username, and then my script will fill in the domain from the url.
So like given:
http://www.yahoo.com
news.yahoo.com
us2.photos.yahoo.com
yahoo.com
, code will always grab just yahoo.com ?
I've searched and can't find any simple solutions on this ..anyone?
So like given:
http://www.yahoo.com
news.yahoo.com
us2.photos.yahoo.com
yahoo.com
, code will always grab just yahoo.com ?
I've searched and can't find any simple solutions on this ..anyone?
maybe something like this would work :
simple, but effective.
Code: Select all
$url = 'www.yahoo.com';
$url_dump = explode(".",$url);
$i = count($url_dump) - 1;
$b = count($url_dump);
echo 'the domain is '.$url_dump[$i].'.'.$url_dump[$b];- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
Code: Select all
$url = 'www.news.yahoo.com';
$url_dump = explode(".",$url);
$i = count($url_dump) - 2;
$b = count($url_dump) - 1;
echo 'the domain is '.$url_dumpї$i].'.'.$url_dumpї$b];what if the domain was:
http://www.test.co.uk
your method would only print co.uk
just another glitch to think about
http://www.test.co.uk
your method would only print co.uk
just another glitch to think about
ew... good point. i'm sure there might be a library of possible domain name extensions that you could use as a guide.. If (count($url_dump) - 1 . count($url_dump) - 2 == $this_extension) then $url_dump -2, $url_dump -3.
no, that isn't exaclty right, but ya get the picture. might would work.. might.. damn you tim!@#
no, that isn't exaclty right, but ya get the picture. might would work.. might.. damn you tim!@#