O'Reilly logo

PHP for Teens by Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing to Files

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:

fwrite($handle, $string)

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required