xiaodao
01-10-2006, 07:38 PM
hi
how do you find out the extention of a domain name?
thanks
how do you find out the extention of a domain name?
thanks
|
||||
how to find our the extention of a domain namexiaodao 01-10-2006, 07:38 PM hi how do you find out the extention of a domain name? thanks ralph l mayo 01-10-2006, 07:42 PM preg_match('/.*\.(.*)/', 'del.icio.us', $tld); echo $tld[1]; // us Is this what you mean? xiaodao 01-10-2006, 07:45 PM what i want is actually for example yayaya.com i want to find out its extention is .com not .net or .org ralph l mayo 01-10-2006, 08:01 PM edit for a better regex that matches things like co.uk (still kinda flawed) $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); xiaodao 01-10-2006, 11:56 PM well, how to build a function to check com,net,org,us,info,cc,com.sg? Velox Letum 01-11-2006, 01:10 AM <?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). ?> Element 01-11-2006, 07:38 PM In addition to your problem, using Velox's 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!"; } ?> |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum