住在键盘上
班上:
class DomainChecker
{
private $domains;
public function __construct( $domainlist )
{
$this->domains = json_decode( $domainlist );
}
public function Exists( $domain, $tld )
{
return
isset($this->domains->$domain) &&
isset($this->domains->$domain->$tld) &&
$this->domains->$domain->$tld != 'available';
}
public function ListAll()
{
$result = '';
foreach($this->domains as $domainname => $domain)
foreach($domain as $tldname => $tld)
$result .= "$domainname.$tldname\t$tld\n";
return $result;
}
}
用法:
$domainchecker = new DomainChecker('{"Dina-Kar":{"com":"available"},"DinaKarPool":{"com":"available"},"DinaKarStore":{"com":"available"},"DinaKarOnline":{"com":"available"},"DinaKarParts":{"com":"available"},"DinaKarJack":{"com":"available"},"DinaKarTunes":{"com":"available"},"DinaKarSmart":{"com":"available"},"DinaKarWash":{"com":"available"},"DinaKarRound":{"com":"available"}}');
$domain = 'Pome-Tek';
$tld = 'com';
if( $domainchecker->Exists( $domain, $tld ))
echo "$domain.$tld is not available\n\n";
else
echo "$domain.$tld is available\n\n";
echo $domainchecker->ListAll();
输出:
Pome-Tek.com is available
Dina-Kar.com available
DinaKarPool.com available
DinaKarStore.com available
DinaKarOnline.com available
DinaKarParts.com available
DinaKarJack.com available
DinaKarTunes.com available
DinaKarSmart.com available
DinaKarWash.com available
DinaKarRound.com available