For more information about how to locate a character pointer, see. & Lt ;? Php?handlefopen (many.txt, r); read 1st rows first. after reading, the pointer is in the last row $ bufferfgets ($ handle, 1024); read 1st rows of content echo & nbsp; $ buffer & nbsp ;. & l a question about how to locate a character pointer.
$ Handle = fopen ("many.txt", "r ");
// Read 1st rows first. after reading, the pointer is in the last row.
$ Buffer = fgets ($ handle, 1024); // Read 1st rows of content
Echo $ buffer ."
";
// Move the pointer 5 bytes backward
Echo ftell ($ handle )."
";
Fseek ($ handle, 6, seek_cup); // The pointer moves 6 bytes backward.
// Read a row
$ Buffer = fgets ($ handle, 1024); // read the content of the second row.
Echo $ buffer ."
";
// Return the pointer to the start of the file and re-read the 1st rows because the absolute position is 0.
Fseek ($ handle, 0 );
// Read a row of data. because the pointer returns to the beginning of the file, 1st rows of data will be read.
$ Buffer = fgets ($ handle, 1024); // Read 1st lines of text
Echo $ buffer ."
"; // Output read content
Fclose ($ handle); // close the file
?>
After the program reads the file by row for the first time, the file pointer should be at the end of the first line. If you move the pointer back, it should be in the second line. Why does the program result show that the file pointer is moved to the second position in the first line, which is equivalent to moving the pointer from the beginning. However, the function parameter clearly moves six positions from the current position.
Here comes the second line of many.txt that I can play at will, because only the first line of the program results are used.
Name: zhang san, age 15, Gender: Male
Llllllllllllllllllllllllllllll
Buffer fseek
------ Solution --------------------
SEEK_CUR
And should be capitalized
------ Solution --------------------
Yes SEEK_CUR
Instead of seek_cup
Seek_cup can only be 0 when blocking errors
That is, SEEK_SET.