Where is the file header?

Source: Internet
Author: User
The "R" read-only mode opens, pointing the file pointer to the file header.

This is where the head of the file is.

For example, the content of a file is ABC,

The so-called file header refers to the front of the ABC position, or a letter this position ...

Where is the so-called EOF, the C position, or the position behind ABC ....

============
For example, we often use fgetc to read files, one character at a time,
$FP =fopen ("data.html", "R");
if (! $fp) {
echo "Can ' t open the file!";
}else{
while (!feof ($fp)) {
$char =fgetc ($FP);
echo $char. "
";
}
}
?>
is the file header in the A-letter position, not the position in front of a,
Then the fgetc is executed once, the pointer moves down one bit, so when the letter C is read,
The pointer is at the back of C, that is, the file's EOF, at this time feof ($FP) is true, the program does not execute?


Reply to discussion (solution)

The so-called file header refers to the position of the front of ABC

The so-called EOF is the position behind ABC.
while (!feof ($fp)) {
Echo Ftell ($FP), "; I think we should see it clearly.
$char =fgetc ($FP);
echo $char. "
";
}

That's not right. Since the first print out 0 ....

That 0 should be the location of the letter a ... The tail is the one behind ABC ...

After all you only print out 4 positions,
A,b,c and EOF, respectively ...

Chinese, Chinese.

Chinese what ah haha.

First time Moderator Error

  • 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.