Check if the "end-of-file" (EOF) has been reached in PHP

Description

The following code shows how to check if the "end-of-file" (EOF) has been reached.

Example


/*from   w  w  w  .  ja v  a 2 s. com*/
<?php
    $file = fopen("test.txt", "r");

    //Output a line of the file until the end is reached
    while(! feof($file)){
      echo fgets($file). "<br />";
    }

    fclose($file);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    File »




Directory
DirectoryIterator
Drive
File
File Permission
File Read Save
FileSystemIterator
Path
Zip