From the course: PHP Techniques: Working with Files and Directories

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Moving the file pointer

Moving the file pointer - PHP Tutorial

From the course: PHP Techniques: Working with Files and Directories

Start my 1-month free trial

Moving the file pointer

- [Instructor] As we've been working, you may have noticed that PHP keeps track of our position inside an open file. For example, when we used fget PHP kept track of which lines had already been returned. When we wrote to a file more than once, PHP kept track of where we left off each time. It does that using the file pointer. The file pointer is similar to the cursor in a word processing application. You can move the file pointer forward, and backwards through the characters in a file, and you can choose a position to start reading or writing from the file. There's one important difference though, unlike the cursor in a word processing program, the file pointer overwrites text. If you choose a position in the middle of a file and write 10 characters of text, PHP would replace the 10 characters that were there before. It does not insert the new characters and shift the old ones over like a word processor does. We're…

Contents