我写了一个检查feof函数的php脚本如果文件指针处于EOF或发生错误(包括套接字超时),返回TRUE;否则返回FALSE。我的问题是在文件结束之前没有feof()的返回值吗?
是我的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 =层叠样式表
超文本标记语言
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
---------------------
您的问题无效。false
回显为空字符串,true
回显为1