PHP feof()Functions
Complete PHP Filesystem Reference Manual
Definition and Usage
The feof() function checks whether the end of file (EOF) has been reached.
Returns TRUE if an error occurs or if the file pointer has reached the end of the file (EOF), otherwise returns FALSE.
Syntax
feof(file)
| Parameter | Description |
|---|---|
| file | Required. Specifies the open file to check. |
Tips and Notes
Tip:The feof() function is useful for looping through data of unknown length.
Example
The following example outputs each line of the file until the last line ends:
Example
$file = fopen("test.txt", "r");
//Output each line of the file until the end of the file
while(! 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.
Complete PHP Filesystem Reference Manual Other Extensions