Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-10-2006, 07:38 PM   PM User | #1
xiaodao
Regular Coder

 
Join Date: Sep 2004
Posts: 713
Thanks: 6
Thanked 2 Times in 2 Posts
xiaodao is an unknown quantity at this point
how to find our the extention of a domain name

hi
how do you find out the extention of a domain name?
thanks
__________________
flying dagger
xiaodao is offline   Reply With Quote
Old 01-10-2006, 07:42 PM   PM User | #2
ralph l mayo
Regular Coder

 
ralph l mayo's Avatar
 
Join Date: Nov 2005
Posts: 951
Thanks: 1
Thanked 31 Times in 29 Posts
ralph l mayo is on a distinguished road
PHP Code:
preg_match('/.*\.(.*)/''del.icio.us'$tld);
echo 
$tld[1]; // us 
Is this what you mean?
ralph l mayo is offline   Reply With Quote
Old 01-10-2006, 07:45 PM   PM User | #3
xiaodao
Regular Coder

 
Join Date: Sep 2004
Posts: 713
Thanks: 6
Thanked 2 Times in 2 Posts
xiaodao is an unknown quantity at this point
what i want is actually for example
yayaya.com
i want to find out its extention is .com not .net or .org
__________________
flying dagger
xiaodao is offline   Reply With Quote
Old 01-10-2006, 08:01 PM   PM User | #4
ralph l mayo
Regular Coder

 
ralph l mayo's Avatar
 
Join Date: Nov 2005
Posts: 951
Thanks: 1
Thanked 31 Times in 29 Posts
ralph l mayo is on a distinguished road
edit for a better regex that matches things like co.uk (still kinda flawed)
PHP Code:
$domain 'www.example.com';
preg_match('/\.([a-zA-Z]{2,3}\.[a-zA-Z]{2}|[a-zA-Z]{2,4})$/'$domain$tld);
print_r($tld); 

Last edited by ralph l mayo; 01-11-2006 at 12:38 AM..
ralph l mayo is offline   Reply With Quote
Old 01-10-2006, 11:56 PM   PM User | #5
xiaodao
Regular Coder

 
Join Date: Sep 2004
Posts: 713
Thanks: 6
Thanked 2 Times in 2 Posts
xiaodao is an unknown quantity at this point
well, how to build a function to check com,net,org,us,info,cc,com.sg?
__________________
flying dagger
xiaodao is offline   Reply With Quote
Old 01-11-2006, 01:10 AM   PM User | #6
Velox Letum
Senior Coder

 
Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
Velox Letum is an unknown quantity at this point
PHP Code:
<?php
function get_tld($url) {
     
$url parse_url($url);
     return 
substr($url['host'], strripos($url['host'], '.') + 1);
}
echo 
get_tld('http://foo.com/bar.php?foobar=barfoo'); // Returns 'com' (without quotes).
?>
__________________
"$question = ( to() ) ? be() : ~be();"
Velox Letum is offline   Reply With Quote
Old 01-11-2006, 07:38 PM   PM User | #7
Element
Regular Coder

 
Element's Avatar
 
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
Element is an unknown quantity at this point
In addition to your problem, using Velox's code...


PHP Code:
<?php 
function valid_tld($url) {
     
$valid_tld = array('com''net''org'); // Valid TLDs 
     
$url parse_url($url); // URL parts
     
$tld substr($url['host'], strripos($url['host'], '.') + 1); // TLD 
     
if(in_array($tld$valid_tld)) { return true; } else { return false; }


if(
valid_tld("http://example.com/index.php?a=a&b=b")) {
  echo 
"Valid domain!";
}

?>
Element is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 +1. The time now is 04:22 AM.


Advertisement
Log in to turn off these ads.