Easy Tutorial
❮ Func Array Key First Func Directory Dir ❯

PHP feof() Function



Definition and Usage

The feof() function checks if the end-of-file (EOF) has been reached.

It returns TRUE if an error occurs or if the file pointer reaches the end-of-file (EOF), otherwise it returns FALSE.

Syntax

Parameter Description
file Required. Specifies the open file to check.

Tips and Notes

Tip: The feof() function is useful for iterating over data of unknown length.


Example

The following example outputs each line of the file until the last line is reached:

Example

<?php
$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.

❮ Func Array Key First Func Directory Dir ❯