feof() function in PHP

PHPProgrammingServer Side Programming

The feof() function tests for end-of-file on a file pointer. It returns TRUE if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns FALSE.

Syntax

feo(file_pointer)

Parameters

  • file_pointer − The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose())

Return

The feof() function returns TRUE if the file pointer is at EOF or an error occurs, otherwise returns FALSE.

Example

<?php
   $file_pointer = @fopen("/myfiles/one.php", "r");
   if ($file_pointer) {
      while (!feof($file_pointer)) {
         $buffer = fgetss($file_pointer, 1024);
         echo $buffer;
      }
      fclose($file_pointer);
   }
?>

Output

First line
raja
Published on 03-Oct-2018 12:23:29
Advertisements