定义

feof()获取文件句柄并检查文件句柄是否已经到达结尾,如果你在文件的结尾则返回true,否则返回false。

 

语法

PHP feof()函数具有以下语法。

feof(file)

 

参数

参数 是否必须 描述
file 需要。 打开的文件

 

返回值

如果发生错误或者已达到文件末尾,此函数返回TRUE。否则返回FALSE。

 

实例

feof()函数检查是否已达到“文件末尾”(EOF)。

<?php
/*
http://www.manongjc.com/article/1775.html
作者:码农教程
*/
$huge_file = fopen(\"VERY_BIG_FILE.txt\", \"r\");
while (!feof($huge_file)) {
   print fread($huge_file, 1024);
}
fclose($huge_file);

?>

 

实例2

以下代码显示如何进行二进制安全文件读取。

<?php
/*
http://www.manongjc.com/article/1775.html
作者:码农教程
*/
$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);
?>
收藏 打印