PHP feof() 函數

定義和用法
feof() 函數檢查是否已到達檔末尾(EOF)。
如果出錯或者檔指針到了檔末尾(EOF)則返回 TRUE,否則返回 FALSE。
語法
feof(file)
參數 | 描述 |
---|---|
file | 必需。規定要檢查的打開檔。 |
提示和注釋
提示:feof() 函數對遍曆長度未知的數據很有用。
實例
<?php
$file = fopen("test.txt", "r");
//Output a line of the file until the end is reached
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
$file = fopen("test.txt", "r");
//Output a line of the file until the end is reached
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
上面的代碼將輸出:
Hello, this is a test file.
There are three lines here.
This is the last line.
There are three lines here.
This is the last line.
