Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

 
 
Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 2006-10-14, 06:08 PM   #2
matt
Trying is the first step towards failure
 
Join Date: Apr 2003
Location: Australia
Posts: 123
Send a message via ICQ to matt
Here's a really ugly way to do it... I'm sure there's a better one but this should work. Something like:
PHP Code:
$tld = array('com','net','org','co'); // might need to add more
$bits explode('.',$host);

if(
$bits[0] == 'www')
array_shift($bits); // the www exists, but it's irrelevant so shift it off the start

if(count($bits) > 4)
{
//some crazy domain action with at least 2 subdomain levels, i'd give them the shaft... but you can reuse what's below for more subdomain levels if ya want to.
}
elseif(
count($bits) == 4)
{
  if(
array_search($bits[2],$tld) !== false)
  {
  
// third bit is a tld, so this is a domain.com.au with a subdomain
  
$domain $bits[1] .'.'$bits[2] .'.'$bits[3];
  }
  else
  {
  
//some crazy domain action with at least 2 subdomain levels or it's an ip, i'd give them the shaft
  
}
}
elseif(
count($bits) == 2)
{
//can only have the name + tld
$domain $bits[0] .'.'$bits[1];
}
elseif(
array_search($bits[1],$tld) !== false)
{
//there are three parts, second one is a tld, so this is a valid domain
$domain $bits[0] .'.'$bits[1] .'.'$bits[2];
}
else
{
//there are three parts, but no tld as the second one, must be using a subdomain.
$domain $bits[1] .'.'$bits[2];

Hope that helps
__________________
Link List Land - Linklist Creation, Design and Implementation.
matt is offline   Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:09 AM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc