Feof () function guessing _php tutorial in PHP

Source: Internet
Author: User
< 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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.