|
 |
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
|
|
01-10-2006, 07:38 PM
|
PM User |
#1
|
|
Regular Coder
Join Date: Sep 2004
Posts: 713
Thanks: 6
Thanked 2 Times in 2 Posts
|
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
|
|
|
|
01-10-2006, 07:42 PM
|
PM User |
#2
|
|
Regular Coder
Join Date: Nov 2005
Posts: 951
Thanks: 1
Thanked 31 Times in 29 Posts
|
PHP Code:
preg_match('/.*\.(.*)/', 'del.icio.us', $tld); echo $tld[1]; // us
Is this what you mean?
|
|
|
01-10-2006, 07:45 PM
|
PM User |
#3
|
|
Regular Coder
Join Date: Sep 2004
Posts: 713
Thanks: 6
Thanked 2 Times in 2 Posts
|
what i want is actually for example
yayaya.com
i want to find out its extention is .com not .net or .org
__________________
flying dagger
|
|
|
01-10-2006, 08:01 PM
|
PM User |
#4
|
|
Regular Coder
Join Date: Nov 2005
Posts: 951
Thanks: 1
Thanked 31 Times in 29 Posts
|
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..
|
|
|
01-10-2006, 11:56 PM
|
PM User |
#5
|
|
Regular Coder
Join Date: Sep 2004
Posts: 713
Thanks: 6
Thanked 2 Times in 2 Posts
|
well, how to build a function to check com,net,org,us,info,cc,com.sg?
__________________
flying dagger
|
|
|
01-11-2006, 01:10 AM
|
PM User |
#6
|
|
Senior Coder
Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
|
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();"
|
|
|
01-11-2006, 07:38 PM
|
PM User |
#7
|
|
Regular Coder
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
|
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!";
}
?>
|
|
|
 |
Jump To Top of Thread
| Thread Tools |
|
|
| 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
HTML code is Off
|
|
|
All times are GMT +1. The time now is 04:22 AM.
|
Advertisement Log in to turn off these ads. |
|
|
|
|
|
|
|
|
|
|