Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

feof()

Example

Open the file and read lines until the end-of-file (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);
?>

Definition and Usage

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

Tip: This function is helpful for iterating through data of unknown length.

Syntax

feof(file)

Parameter Values

Parameter

Description

file

Mandatory. Specifies an open file to check.

Technical Details

Return Value:

Returns TRUE if the end-of-file (EOF) is reached or if an error occurs; FALSE otherwise.

PHP Version:

4.0+