Latest web development tutorials

PHP feof() 函數

PHP Filesystem 參考手冊 完整的PHP Filesystem參考手冊

定義和用法

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

上面的代碼將輸出:

Hello, this is a test file.
There are three lines here.
This is the last line.


PHP Filesystem 參考手冊 完整的PHP Filesystem參考手冊