feof
Test whether the file pointer reaches the end of the file
feof()
function detects whether the end of the file has been reached (eof).
If the file pointer reaches EOF or an error occurs, it will return TRUE, otherwise an error will be returned (including socket timeout), and FALSE will be returned in other cases.
<?php $file = fopen ( "test.txt" , "r" ) ; //Output all lines in the text until the end of the file. While ( ! feof ( $file ) ) { echo fgets ( $file ) . "<br />" ; } fclose ( $file ) ; ?>
Output:
Hello, this is a test file. There are three lines here. This is the last line.
feof ( file )
parameter | describe |
---|---|
file | Required. Specify the opening file to be checked. |
The file parameter is a file pointer. This file pointer must be valid and must point to a file that was successfully opened by fopen()
or fsockopen()
(but has not been closed fclose()
).