Home > Article > Backend Development > php feof function
If the file pointer reaches EOF or an error occurs, it returns TRUE, otherwise it returns an error, including socket timeout, and in other cases, returns FALSE.
Syntax: feof(file)
Parameter description
file required, specifies the open to be checked File.
Note: 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 by fclose().
PHP example code As follows:
// if file can not be read or doesn’t exist fopen function returns false
$file = @fopen("no_such_file", "r");
// false from fopen will issue warning and result in infinite loop here
while (!feof($file)) {
}
fclose($file);
?>
$fh = fopen("/home/www.phpfensi.com/data/users.txt", "rt");
while (!feof($fh)) echo fgets($fh);
fclose($fh) ;
?>