This is a supremely useful set of functions, particularly for data sets too small or scattered to merit the use of a database. File reading is pretty safe unless you keep unencrypted passwords lying around, but file writing can be quite unsafe.
A file manipulation session might involve the following steps:
1. Open the file for read/write.
2. Read in the file.
3. Close the file (may happen later).
4. Perform operations on the file contents.
5. Write results outEach step has a corresponding PHP filesystem function.
This archetypal example illustrates some subtleties of the syntax for manipulating file contents:
$fd = fopen($filename, “r+”)
or die(“Can’t open file $filename”);
$fstring = fread($fd, filesize($filename));
$fout = fwrite($fd, $fstring);