PHPfeof test whether the file pointer has reached the end of the file. EOF is a very important concept. almost every mainstream programming language provides corresponding built-in functions to verify whether the parser has reached the file EOF. In PHP, this function is feof (). Feo EOF is a very important concept. almost every mainstream programming language provides corresponding built-in functions to verify whether the parser has reached the file EOF. In PHP, this function is feof (). The feof () function is used to determine whether it reaches the end of the resource. It is often used in file I/O operations. The format is:
Int feof (string resource)
The instance code is as follows:
$ Fh = fopen ("/home/www/data/users.txt", "rt ");
While (! Feof ($ fh) echo fgets ($ fh );
Fclose ($ fh );
?>
Bool feof (resource $ handle): Tests for end-of-file on a file pointer
The original words above the php manual.
I used this for convenience.
// If file can not be read or doesnt exist fopen function returns FALSE
$ File = @ fopen ("no_such_file", "r ");
// FALSE from fopen will issue warning and result in infinite loop here
While (! Feof ($ file )){
}
Fclose ($ file );
?>
Indeed, this is relatively simple to use. However, if the above variable $ file is not a valid file pointer or has been disabled by fclose.
In the sixth line of the program, a waring will be generated, and the concurrent life and death loop will be generated.
Why?
The reason is
Returns TRUE if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns FALSE.
Therefore, for the sake of security, it is best to add a judgment when using the above code, is_resource is relatively safe
Http://www.bkjia.com/PHPjc/486144.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486144.htmlTechArticleEOF is a very important concept. almost every mainstream programming language provides corresponding built-in functions to verify whether the parser has reached the file EOF. In PHP, this function is feof (). Feo...