feof函数在文件结束前不返回false

时间:2014-08-12 05:14:52

标签: php

我编写用于检查feof函数的php脚本 根据php.net如果文件指针处于EOF或发生错误(包括套接字超时),则返回TRUE;否则返回FALSE。 我的问题是,在文件结束之前,feof()没有eturn值吗?

这是我的php文件

<?php
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
// Output one line until end-of-file


echo "----------------------<br>";
echo "end of file is ".feof($myfile)."<br>";
echo "---------------------<br>";


while(!feof($myfile))
{
   echo fgets($myfile) . " ----- "."end of file is ".feof($myfile)."<br>";
}

echo "----------------------<br>";
echo "end of file is ".feof($myfile)."<br>";
echo "---------------------<br>";

fclose($myfile)

?>

此文本文件(webdictionary.txt)

  

AJAX =异步JavaScript和XML
  CSS =层叠样式表
  HTML =超文本标记语言
  PHP = PHP超文本预处理器
  SQL =结构化查询语言SVG =可缩放矢量图形
  XML =可扩展标记语言

这是php输出

----------------------
end of file is 
---------------------
AJAX = Asynchronous JavaScript and XML ----- end of file is 
CSS = Cascading Style Sheets ----- end of file is 
HTML = Hyper Text Markup Language ----- end of file is 
PHP = PHP Hypertext Preprocessor ----- end of file is 
SQL = Structured Query Language ----- end of file is 
SVG = Scalable Vector Graphics ----- end of file is 
XML = EXtensible Markup Language ----- end of file is 1
----------------------
end of file is 1
---------------------

1 个答案:

答案 0 :(得分:1)

您的问题无效。 false以空字符串形式回显,true1的形式回声。