feof() 对未知文本长度的的数据非常有用,我以前不知道-女黑客 - Powered by Discuz! Archiver

nvhack 发表于 2016-10-23 12:58:54

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);
?>


nvhack 发表于 2016-10-23 12:59:34

<!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]
查看完整版本: feof() 对未知文本长度的的数据非常有用,我以前不知道