-5
{"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"}}

我需要输出,因为 Dina-Kar.com 可用。并且需要使用 PHP 脚本动态运行循环以获取所有可用值。

你能帮我这样说吗?

4

1 回答 1

0

住在键盘上

班上:

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
于 2012-10-27T10:02:57.113 回答