我有一些假設打印域名服務器的代碼。然而在印刷它們時它給了我這樣的:使用dns_get_record()的結果
array(5) {
[0]=>
array(5) {
["host"]=>
string(7) "php.net"
["type"]=>
string(2) "NS"
["target"]=>
string(19) "remote1.easydns.com"
["class"]=>
string(2) "IN"
["ttl"]=>
int(32)
}
[1]=>
array(5) {
["host"]=>
string(7) "php.net"
["type"]=>
string(2) "NS"
["target"]=>
string(19) "remote3.easydns.com"
["class"]=>
string(2) "IN"
["ttl"]=>
int(32)
}
[2]=>
array(5) {
["host"]=>
string(7) "php.net"
["type"]=>
string(2) "NS"
["target"]=>
string(15) "ns2.easydns.com"
["class"]=>
string(2) "IN"
["ttl"]=>
int(32)
}
[3]=>
array(5) {
["host"]=>
string(7) "php.net"
["type"]=>
string(2) "NS"
["target"]=>
string(15) "ns1.easydns.com"
["class"]=>
string(2) "IN"
["ttl"]=>
int(32)
}
[4]=>
array(5) {
["host"]=>
string(7) "php.net"
["type"]=>
string(2) "NS"
["target"]=>
string(19) "remote2.easydns.com"
["class"]=>
string(2) "IN"
["ttl"]=>
int(32)
}
}
我知道這是一個數組,但是我只希望它打印每個域名服務器
remote2.easydns.com
ns1.easydns.com
ns2.easydns.com
remote1.easydns.com
等
這是我當前的代碼:
<?php
$result = dns_get_record("php.net", DNS_NS);
echo '<pre>';
var_dump($result);
echo '</pre>';
?>
Print_r做了一件非常相似的事情。
'主機'鍵將輸出'php.net'的所有結果。你想輸出'target'鍵。 –
是的,這是一個愚蠢的錯誤。謝謝。 –
天哪不知道我爲什麼這麼想。我現在試圖使用gethostbyname()將主機名解析爲IP,但它僅打印:pastebin.com/1Gs1kyY4而不是完整的IP。我在這裏做錯了什麼? pastebin.com/9u5Q9C79 – user1372896