PHP uses the feof () function to read files,
This article mainly introduces how to use the feof () function to read files in PHP, compares the correct and incorrect usage in the form of examples, and clarifies the usage skills of the feof () function, for more information, see
This example describes how to use the feof () function to read files in PHP. Share it with you for your reference. The usage is as follows:
Feof applies to PHP 4 and PHP 5
-It is used to test whether the file pointer has reached the end of the file.
If the server does not close the connection opened by fsockopen (), feof () waits until it times out and returns TRUE. The default timeout limit is 60 seconds. You can use stream_set_timeout () to change this value.
The file pointer must be valid and must be directed to a file successfully opened by fopen () or fsockopen () (not closed by fclose ).
If the passed file pointer is invalid, it may be in an infinite loop, because EOF does not return TRUE.
Example #1 Example of using feof () with invalid file pointer:
<? Php // if the file cannot be read or does not exist, the fopen function returns FALSE $ file = @ fopen ("http://www.manongjc.com/article/1329.html", "r "); // FALSE from fopen generates a warning message and falls into an infinite loop here. while (! Feof ($ file) {}fclose ($ file);?>
Example:
<? Php $ file = fopen ($ _ SERVER ['document _ root']. "/me/test.txt", "r"); // http://www.manongjc.com/article/1328.html//all the lines in the Output Folder go directly to the file. While (! Feof ($ file) {echo fgets ($ file). "<br/>" ;}fclose ($ file);?>
Output:
Hello, this is a test file.
There are three lines here.
This is the last line.