feof() 对未知文本长度的的数据非常有用,我以前不知道
PHP 检查 End-Of-File - feof()feof() 函数检查数据是否已到达 "end-of-file" (EOF)。
feof() 对于遍历未知长度的数据很有用。
下例逐行读取 "webdictionary.txt" 文件,直到 end-of-file:
实例
<?php
$myfile = fopen("read.txt", "r") or die("Unable to open file!");
// 输出单行直到 end-of-file
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
?>
<!DOCTYPE html>
<html>
<body>
<?php
$myfile = fopen("read.txt", "r") or die("Unable to open file!");
// 输出一行直到 end-of-file
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
?>
</body>
</html>
页:
[1]