PHP feof() Function

❮ PHP Filesystem Reference

Example

Open file, read lines - until EOF is reached:

<?php
$file = fopen("test.txt", "r");

//Output lines until EOF is reached
while(! feof($file)) {
  $line = fgets($file);
  echo $line. "<br>";
}

fclose($file);
?>
Run Example »

Definition and Usage

The feof() function checks if the "end-of-file" (EOF) has been reached for an open file.

Tip: This function is useful for looping through data of unknown length.

Syntax

feof(file)

Parameter Values

Parameter Description
file Required. Specifies an open file to check


Technical Details

Return Value: TRUE if EOF is reached or an error occurs, FALSE otherwise
PHP Version: 4.0+

❮ PHP Filesystem Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.