Question: do not understand ftell () solutions

Source: Internet
Author: User
Question: do not understand ftell () & lt ;? Php $ fp = fopen ('exa', 'r'); $ data = fgets ($ fp, 15); echoftell ($ fp); fclose ($ fp );? & Gt; output in this example: 13 if the value is changed to a relatively large number such as 1046, 13 is also output; if the value is changed to 13, 12 is output to ask new users: do not understand ftell ()
$ Fp = fopen ('exa', 'r ');

$ Data = fgets ($ fp, 15 );

Echo ftell ($ fp );

Fclose ($ fp );
?>

Output in this example: 13
If 15 is changed to a large number such as 1046, 13 is also output;
If 15 is changed to 13, 12 is output.


What is going on?

------ Solution --------------------
First, the pointer width of the row in your 'exa' file is 13, and the pointer starts from 0. Therefore, if you select 15 or larger, you only need to exceed the width of the row, only the maximum width, that is, 13, can be output.
Second, because the pointer is calculated from 0, $ data = fgets ($ fp, num); and the pointer actually starts from 0, then ftell ($ fp) the value must be a num-1, such as your fgets ($ fp, 5), then ftell ($ fp) will be 4.
Therefore, if you change 15 to 13, the output is 12. because 13 does not exceed the maximum width, the output is 13-1.

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.