feof
測試文件指針是否到了文件結束的位置
feof()函數檢測是否已到達文件末尾(eof)。
如果文件指針到了EOF 或者出錯時則返回TRUE,否則返回一個錯誤(包括socket 超時),其它情況則返回FALSE。
<?php
$file = fopen ( "test.txt" , "r" ) ;
//輸出文本中所有的行,直到文件結束為止。
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.
feof ( file )
| 參數 | 描述 |
|---|---|
| file | 必需。規定要檢查的打開文件。 |
file參數是一個文件指針。這個文件指針必須有效,並且必須指向一個由fopen()或fsockopen()成功打開(但還沒有被fclose()關閉)的文件。