1. Home
  2. Computing & Technology
  3. PHP / MySQL

Feof PHP Function

By Angela Bradley, About.com

Definition: The feof () PHP Function is used to test for the end of a file. It is often used in a loop, to keep a process going until everything in the document has been processed. It is phrased as: feof($file) but more often seen as !feof($file).
Examples:
<?php
$myFile = "YourFile.txt";
$handle = fopen($myFile, 'r');
while (!feof($handle))
{
$data = fgets($handle, 512);
echo $data;
echo "<br>";
}
fclose($handle);
?>
This returns the data from the file as long as feof () is not true. When it is true (you have reached the end of the file) then the loop is exited.

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. PHP Feof - PHP end of file - Feof php function

©2008 About.com, a part of The New York Times Company.

All rights reserved.