<?php
class domain_finder {
var $alternative_tlds=array("com","co.uk","me.uk","ws","org","org.uk","net","net.uk");
var $head_tags=array("<h2>","</h2>");
var $result;
function domain_finder($domain="")
{
if ($domain=="") return true;
$cleaned_domain=$this->clean($domain);
$buf=$this->head_tags[0].$this->domain_exists_pretty_print($cleaned_domain).$this->head_tags[1];
$buf.=$this->check_alternative_domains($cleaned_domain);
$this->result=$buf;
}
function domain_exists_pretty_print($domain)
{
$buf="$domain is ";
if ($result=$this->domain_exists($domain)) $buf.= "not ";
$buf.="available.";
return $buf;
}
function domain_exists($domain)
{
exec("host -t ns $domain",$host_result);
if (preg_match("/host.*not found/",strtolower($host_result[0]))) return false;
return true;
}
function check_alternative_domains($domain)
{
$buf="<p>Alternative domains:</p>rn<ul>rn";
$d=substr($domain,0,strpos($domain,".")+1); //remove everything after last .
foreach($this->alternative_tlds as $tld)
$buf.="<li>".$this->domain_exists_pretty_print($d.$tld)."</li>";
$buf.="</ul>";
return $buf;
}
function clean($domain)
{
$buf=strtolower($domain);
//remove leading www.
if (preg_match("/^www./",$domain)) $buf=substr($buf,4);
return $buf;
}
}
?>
|
|