我有一个循环,我遍历许多域并且我ping主题:循环如下:
foreach ($rows[1] as $domains){
$domain='www.'.$domains;
$output = shell_exec('ping -c1 '.$domain.'');
echo "<pre>$output</pre>";
}
我的问题:是否可以为每个循环域写出结果IP地址?
答案 0 :(得分:2)
当然,只需使用gethostbyname(PHP文档)。例如:
foreach ($rows[1] as $domains){
$domain='www.'.$domains;
$output = shell_exec('ping -c1 '.$domain.'');
echo "<pre>$output</pre>";
echo gethostbyname($domain);
}
答案 1 :(得分:0)
试试这个
foreach ($rows[1] as $domains){
$domain='www.'.$domains;
$ip = gethostbyname($domain);
echo $domain.','.$ip.'\n';
}
//OUPUT HEADERS
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=domains.csv;" );
header("Content-Transfer-Encoding: binary");