PHP Feof () function

PHP

The feof() function returns True if end of file has been reached or an error has occurred. Otherwise it returns False.Syntax:
feof ($file) 
Parameters:Function feof() in PHP only takes one parameter, which is $file. This parameter specifies the file to check for end of file.Return value:Returns TRUE if end of file has been reached or an error has occurred. Otherwise it returns False.Errors and Exceptions :
  • It goes into an infinite loop if the file pointer passed is invalid because the end of the file is not may return True.
  • The feof() function hangs if the connection opened with fsockopen() is not closed by the server.
  • The following programs illustrate the feof() function:Program 1 : In the program below, the file named “singleline.txt” contains only one line of text called “This file is only one line.”  
    // the file is opened using the fopen() function $check = fopen ( "singleline.txt" , "r" ); $seq = fgets ( $check );  
    // Outputs the file line before
    // end of file reached while (! feof ( $check ) ) { echo $seq ; $seq = fgets ( $check ) ; }  
    // the file is closed using the fclose() function fclose ( $check );  
    ?>
    Output:
    This file consists of only a single line. 
    Program 2 : In the following program, the file named "gfg.txt" contains the following text. This is the first line.
    This is the second line.
    This is the third line.  
    // the file is opened using the fopen() function $check = fopen ( "gfg.txt" , "r" ); $seq = fgets ( $check );  
    // Outputs the file line before
    // end of file reached while (! feof ( $check ) ) { echo $seq ; $seq = fgets ( $check ) ; }  
    // the file is closed using the fclose() function fclose ( $check );  
    ?>
    Output:
    This is the first line. This is the second line. This is the third line. 
    Link:
    http: //php.net/manual/en/function.feof.php



    Get Solution for free from DataCamp guru