Home and Learn: PHP Programming Course

Working with Files Introduction


The ability to open up files such as plain text or CSV files is a great asset for you as a programmer. Not every job requires a database with multiple tables, and storing simple data in a text file can be a good alternative. Especially if your web host doesn't allow you to have a database!

In this section, we take a look at the various way you can manipulate files with PHP. We'll start by opening a plain text file.

For this section, we'll be using the file called dictionary.txt, which is amongst the ones you downloaded (in the scripts folder).

Open this file up, and take a look at the contents. It should look like this:

AAS = Alive and smiling
ADN = Any day now
AEAP = As early as possible
AFAIK = As far as I know
AFK = Away from keyboard
AKA = Also known as

It's just a long list of values separated by an equals sign. On the left of the equals sign is an abbreviation, and on the right its meaning. We'll open this text file with PHP code. You'll see different ways to open up and work with this text file. Click below to make a start.

Move on to the Next Part -->

Back to the PHP Contents Page


Email us: enquiry at homeandlearn.co.uk