Chapter 6: Working with Files

Chapter 6: Working with Files

Overview

As your experience in programming grows, the relative importance of data becomes increasingly apparent. You began your understanding of data with simple variables, but learned how simple and more complex arrays can make your programs more flexible and more powerful. However, data stored in the computer's memory is transient, especially in the server environment. It is often necessary to store information in a form that is more permanent than the constructs you have learned so far. PHP provides a number of powerful functions for working with text files. With these skills, you will be able to create extremely useful programs. Specifically, you will learn how to:

  • Open files for read, write, and append access.

  • Use file handles to manipulate text files.

  • Write data to a text file.

  • Read data from a text file.

  • Open an entire file into an array.

  • Modify text data on the fly.

  • Get information about all the files in a particular directory.

  • Get a subset of files based on filenames.