< span="">10.8.4< span="">5.3.15
In the official PHP manual, the function feof () is discussed below, and a number of relevant tests are done.
<<<
<title>Test the feof () function effect in PHP</title> BOOL2STR ( (== "TRUE"} "FALSE" = './7bytesfile ' =(, ' R ' (! ("File open Failed" (= 0;<=();++ (, "File Location".() . ":
\ n " "feof Result:" Before performing a fseek, read operation has not been performed. BOOL2STR (()) . "
\ n " "Current position character:".() . "
\ n " "After performing a file read operation, feof the result:". BOOL2STR (()) . "
\ n " "Ftell () Result:".(). "
\ n " (, 4 "File Location".() . ":
\ n " "feof Result:" Before performing a fseek, read operation has not been performed. BOOL2STR (()) . "
\ n " "Current position character:".() . "
\ n " "After performing a file read operation, feof the result:". BOOL2STR (()) . "
\ n " (, 7 "File Location".() . ":
\ n " "feof Result:" Before performing a fseek, read operation has not been performed. BOOL2STR (()) . "
\ n " "Current position character:".() . "
\ n " "After performing a file read operation, feof the result:". BOOL2STR (()) . "
\ n " ( =(, ' R ' (! ("File open Failed" (!( =( (=== ' FALSE '} ( <<< ?>The speculation in this case is that, in PHP, the implementation of feof () does not directly check the location of the file pointer relative to the file, but instead returns the result based on an identity. This flag is set to "False" after each fseek (), and the identity is set only after the file read operation is performed, based on the results of the file reading.
Based on this speculation, two kinds of code logic can be used.
One method is to not do feof () detection and directly detect the execution result of the content reading function (such as fgetc (), fgets ()).
< span="">< span="">((< span="">< span="">(< span="">< span="">< span="">< span="">< < span=""> /c15> }< span="">
This approach, using PHP is criticized by the function return method, so you have to use "= = =" or "!==" to detect, can not simplify the code into:
< span="">(< span="">< span="">(< span="">)) {}
Another way is to do a file read first and then into the feof () loop:
< span="">< span="">< span="">(< span="">< span="">< span="">< span=""> (! < span="">(< span="">< span="">< span="">< span="">< span="">< /c25>< span=""> (< span="">< span=""> < span=""> < span=""> < span=""> }
After testing, it seems that the former method is more efficient.
http://www.bkjia.com/PHPjc/440135.html www.bkjia.com true http://www.bkjia.com/PHPjc/440135.html techarticle 10.8.4 5.3.15 PHP's official manual, the function feof () under the discussion of a lot, to do some related tests. DOCTYPE HTML HTML head meta http-equiv= "Content-type" content= "Tex ...