feof() function in PHP


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

177 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements