TutsPlus.com has continued their series of posts covering some of the basics of the PHP language with their latest article. In this newest tutorial they cover reading from and writing to files using functionality already included with the language.
In this tutorial, you'll learn several important functions in PHP which are sufficient for all your basic file reading and writing needs. You'll learn how to read a file, write to a file, write to a text file, and check if a file exists.Luckily, PHP provides a lot of functions to read and write data to files. In this tutorial, I'll show you the easiest ways to read data from a local or remote file and how to use flags to write to files exactly how we want.
The tutorial is broken down into several sections:
- checking if a file exists
- reading data from a file
- writing data to a file
- reading and writing data to files
Each section comes with a bit of description and code examples showing it in action. The post wraps up with some final thoughts and "gotchas" that you need to know when working with files in PHP (especially large ones).