Creating new files with php is pretty easy and straightforward. First you need decide what to name the file, which is what I store in the variable ourFileName. The next line does the job of creating the empty document and opening the file so that we can write text to it. The variable stringData holds the text that I would like insert into the new document. The function fwrite does the job of writing text to the new document that we created and only needs to know what the file name is and what data is to be written. Finally fclose closes the file so that it is no longer editable. One thing to note with this is that if you want to create and write to a file in a different directory then you would simply include the directory path in the variable ourFileName. For example if you had a folder called "mynewdocuments" and you wanted to write the file into that directory then ourFileName = "mynewdocuments/mynewfile.txt". Writing files can be alot of fun if you wanted to write web pages on the fly, of course you'd probably want a database to use in conjunction with such a feature - but still cool and fun to play around with.
$ourFileName = "mynewfile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
$stringData = 'Here is the content for this file';
fwrite($ourFileHandle, $stringData);
fclose($ourFileHandle);