【发布时间】:2016-08-08 14:33:36
【问题描述】:
(我在 DOS 中执行我的代码)这是我的代码:
<?php
$handle = fopen("domann.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$ip = gethostbyname($line);
echo "reading: ".$line. " ip: ".$ip ;
}
fclose($handle);
} else {
// error opening the file.
}
?>
我想要这样的东西:
阅读:www.abc.it ip:211.195.239.122
问题不在于 gethostbyname() 函数!! 它必须是 fgets($handle) 中的某些内容,它还为读取的每一行返回一个 \n
解决方案在这里:
$handle = fopen("file.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$line=str_replace("\r\n","",$line);
$ip = gethostbyname($line);
echo "reading: ".$line." ip: ".$ip;
echo "\n";
}
fclose($handle);
} else {
echo "connection error";
}
【问题讨论】:
-
您分享的代码有什么问题?错误?
-
应该可以。也许在
$line上做一个var_dump看看它是什么 -
和
domann.txt的内容和格式未知。 -
我显然又一次置若罔闻。哦,不只是我。你是走路去学校还是怎么的?