为什么这不起作用?- 对于文本文件中的每一行,获取文件内容并检查它是否等于特定内容


Why isn't this working? - for each line in text file get file contents & check if it equals something specific

 <?php
error_reporting(0);
$ctx = stream_context_create(array('http'=>
    array(
        'timeout' => 5,
    )
));
$handle = fopen("ist.txt", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
$check = file_get_contents($line, false, $ctx);
if ($check == 'hi.') {
echo $line;
echo 'yay';
} else {
echo 'ney';
echo $line;
}
}
} else {
echo 'error reading file';
}
fclose($handle);
?>

当我只做了 1 个网址时,它就有效了。

基本上它所做的是打印出 neyhttp://mysite/hi.txt

不,该行没有任何空格或任何东西。

File_get_contents给出了页面的来源。要检查内容使用情况:

if (stripos(strtolower($check), 'hi.') !== false) {
}