The text fileGeorge, John, Paul, Ringo

Using your normal editor create an empty text file called names.txt and put these four names in one on each line.

Save the file and upload it to the server in the same location as your PHP pages. If you are using FTP to a proper server make sure that the owner of the file is correctly set to www-data (in Apache) or the file permissions are read and write for everyone (right click on the file in Filezilla).  The text file is now on the server.  Open your browser and click on it and you should see the four names.  This lack of security is one good reason not to use file storage for real data.


Open your PHP template and save it as phpfileread.php.  Paste in this code between the start and end of the <?php ?> tag where code normally goes:

$names = file("./names.txt");

The first line reads the content of the text file into an array called $names (don't worry yet what an array is - as you can see it is a sort of variable).  The function file() needs to be told where the file is and what it is called.  The dot (.) before the file name is a quick way of saying that the file is in the current directory/folder (the same place as the PHP page).

The other line is not new to you.  Save the file, upload it to the server and try it in your browser.  You should see the four names displayed by print_r.

There are better ways to display the data but that comes soon.

The four names output by print_r