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