feof

bool feof(resource file_handle) 

Checks whether EOF has been reached.

Returns:

TRUE if EOF; FALSE on error

Description:

Checks for EOF (end of file) on a file handle obtained from popen(), fopen(), or fsockopen(). This is a useful function when looping through data of unknown length.

Example:

Read from a file until EOF has been reached
<?php 
$fh = fopen ("test.txt", "r"); 

while(! feof ($fh)) {
    $output = htmlspecialchars(fgets($fh, 1024)); 
    echo ("$output<br />"); 
} 

fclose ($fh); 
?> 

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.