Current Location: Home> Function Categories> feof

feof

Test whether the file pointer reaches the end of the file
Name:feof
Category:File system
Programming Language:php
One-line Description:Test whether the file pointer reaches the end of the file.

Definition and usage

feof() function detects whether the end of the file has been reached (eof).

If the file pointer reaches EOF or an error occurs, it will return TRUE, otherwise an error will be returned (including socket timeout), and FALSE will be returned in other cases.

Example

 <?php
$file = fopen ( "test.txt" , "r" ) ;

//Output all lines in the text until the end of the file.
While ( ! feof ( $file ) )
  {
  echo fgets ( $file ) . "<br />" ;
  }

fclose ( $file ) ;
?>

Output:

 Hello, this is a test file. 
There are three lines here. 
This is the last line.

grammar

 feof ( file )
parameter describe
file Required. Specify the opening file to be checked.

illustrate

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 fclose() ).

Similar Functions
Popular Articles