Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 循环通过get_dns_记录_Php_Arrays - Fatal编程技术网

Php 循环通过get_dns_记录

Php 循环通过get_dns_记录,php,arrays,Php,Arrays,这里有一个正在发生的事情和问题所在的快速摘要。。。 $\u POST['domain\u list']是一个域数组,用户可以输入这些域,并用换行符分隔(因此在\n上进行分解) 第一个var转储给了我: array(3) { [0]=> string(11) "google.com " [1]=> string(17) "websolutions.com " [2]=> string(12) "facebook.com" } 这就是我想要的-我在文本区域中输入的3个主机名 因

这里有一个正在发生的事情和问题所在的快速摘要。。。 $\u POST['domain\u list']是一个域数组,用户可以输入这些域,并用换行符分隔(因此在\n上进行分解) 第一个var转储给了我:

array(3) { [0]=> string(11) "google.com " [1]=> string(17) "websolutions.com " [2]=> string(12) "facebook.com" } 
这就是我想要的-我在文本区域中输入的3个主机名

因此,第一个foreach在该数组中循环,并将每个主机名分配给dns\u get\u record函数

这就导致了我所面临的问题——内部的两个循环拉IP和名称服务器,只拉最后一个域。因此,这两个var转储看起来像:

array(5) { ["host"]=> string(12) "facebook.com" ["type"]=> string(1) "A" ["ip"]=> string(13) "173.252.120.6" ["class"]=> string(2) "IN" ["ttl"]=> int(900) } Hostname: facebook.com IP: 173.252.120.6
array(5) { ["host"]=> string(12) "facebook.com" ["type"]=> string(2) "NS" ["target"]=> string(17) "a.ns.facebook.com" ["class"]=> string(2) "IN" ["ttl"]=> int(172528) } Hostname: facebook.com NS: a.ns.facebook.com
array(5) { ["host"]=> string(12) "facebook.com" ["type"]=> string(2) "NS" ["target"]=> string(17) "b.ns.facebook.com" ["class"]=> string(2) "IN" ["ttl"]=> int(172528) } Hostname: facebook.com NS: b.ns.facebook.com
出于某种原因,主循环没有像我期望的那样工作,我期望它在整个$domain数组中循环(您可以在第一个var_转储中看到,它确实在数组中包含所有3个域)

if(isset($\u POST['domain\u list'])){
$domain=$\u POST['domain\u list'];
$domain=explode(“\n”,$domain);
var_dump($domain);
foreach($domain as$entry){
$a\u record=dns\u get\u record($entry,dns\u a);
$nameservers=dns\u get\u记录($entry,dns\u NS);
foreach($arr1){
var_dump(1美元);
回显“主机名:”.$arr1['host'].“IP:”.$arr1['IP'].
; } foreach($arr2名称服务器){ var_dump(2美元); 回显“主机名:”.$arr2['host'].“NS:”.$arr2['target'].
; } } }否则{ echo“失败”; }

提前谢谢

嗯,评论是正确的-我的代码实际上工作正常。我没有得到相同结果的原因是我在文本区域的换行符上爆炸的方式

为了正确获取文本区域中由换行符分隔的值,我更新了此行:

$domain = explode( "\n", $domain );


令人惊讶的是,如此简单的事情竟能让人如此疯狂

据我所知,你的代码运行良好。输出:为我工作,我有所有域的记录。这很有趣。在几个不同的环境中进行测试后,我无法得到这个结果。也许它与服务器有关?
$domain = explode( "\n", $domain );
$domain = explode( "\r\n", $domain );