The feof() function checks whether the end of file (EOF) has been reached.
If an error occurs or the file pointer reaches the end of file (EOF), it returns TRUE, otherwise it returns FALSE.
feof(file)
parameter | describe |
---|---|
file | Required. Specifies the open file to be checked. |
Tip: The feof() function is useful for iterating over data of unknown length.
<?php$file = fopen("test.txt", "r");//Output a line of the file until the end is reachedwhile(! feof($file)) { echo fgets($file). "< br />"; }fclose($file);?>
The above code will output:
Hello, this is a test file. There are three lines here. This is the last line.