feof() takes a file handle and returns true if you are at the end of the file or false otherwise.
PHP feof() Function has the following syntax.
feof(file)
Parameter | Is Required | Description |
---|---|---|
file | Required. | Open file to check |
This function returns TRUE if an error occurs, or if EOF has been reached. Otherwise it returns FALSE.
The feof() function checks if the "end-of-file" (EOF) has been reached.
<?PHP
$huge_file = fopen("VERY_BIG_FILE.txt", "r");
while (!feof($huge_file)) {
print fread($huge_file, 1024);
}
fclose($huge_file);
?>
The following code shows how to binary-safe file read.
//from www . jav a2 s.c o m
<?php
// For PHP 5 and up
$handle = fopen("http://www.java2s.com/", "rb");
$contents = stream_get_contents($handle);
fclose($handle);
//OR
$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
?>