0

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
---------------------
Susantha7
  • 898
  • 1
  • 20
  • 38
  • 1
    `feof()` returns a boolean value (`true` or `false`). Echoing it will produce `"1"` for `true` and `""` for `false`. – Sverri M. Olsen Aug 12 '14 at 05:25
  • possible duplicate of [PHP - Get bool to echo false when false](http://stackoverflow.com/questions/4948663/php-get-bool-to-echo-false-when-false) – Lorenz Meyer Aug 12 '14 at 05:27

1 Answers1

1

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

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358