doutang6600 2014-08-11 21:14
浏览 62
已采纳

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

i write php script for check feof function according to php.net Returns TRUE if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns FALSE. my question is there is no eturn value for feof() when there is before the end of file ?

this is my php file

<?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)

?>

this text file(webdictionary.txt)

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

this is php output

----------------------
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条回答 默认 最新

  • douna2917 2014-08-11 21:18
    关注

    Your question is invalid. false echos out as an empty string, and true echos out as 1.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部