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 - PHP Tutorial
From the course: PHP Techniques: Working with Files and Directories
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
-
-
-
Filesystem basics6m 6s
-
Relative paths and magic constants4m 53s
-
Accessing files5m 4s
-
Reading from files4m 52s
-
Reading line by line5m 9s
-
File permissions5m 34s
-
Writing to files5m 5s
-
Writing line returns2m 28s
-
Deleting files2m 38s
-
Moving the file pointer7m 36s
-
Examining file details6m 52s
-
Challenge: Create a log file2m 2s
-
Solution: Create a log file3m 17s
-
-
-
-