Writing to files is almost as simple as loading and closing files. All you need is another function: fwrite(). This naming scheme is getting pretty easy to figure out, huh? Take a look at the fwrite() declaration:
With this function, you can write whatever string you want to a file. Note that we are writing an ASCII file, which means that anything you write to the file is a string, because it will be interpreted as a string when data is later read from the document. fwrite() only works if the $handle was opened for write or append access, as discussed earlier in this chapter.
So let’s create a web page that lets the user append text to the bottom of a file and close it. Let’s start off with the HTML form ...