PHP - Function feof()


Advertisements


Syntax

bool feof ( resource $handle );

Definition and Usage

Tests for end-of-file on a file pointer.

WARNING − If passed file pointer is not valid you may get an infinite loop, because EOF fails to return TRUE.

Parameters

Parameter Description
handle 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 Value

Returns TRUE if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns FALSE.

Example

Following is the usage of this function −

<?php
   if ($f = fopen('myfile.txt', 'r')) do {
      $line = fgets($f);
      echo "$line";
      
      // do any stuff here...
   }
   
   while (!feof($f));
   
   fclose($f);
?>

php_function_reference.htm

Advertisements