JDT |
FREE Downloads |
|
Using PHP to Write the Contents of a Variable to a File |
||||
|
It is sometimes necessary to write the contents of a variable to a file. Here is a simple way to do it in PHP. Assume that the variable '$contents' contains some text, for example, "hello world". If you want to write this content to a file called 'contentsFile.txt, which is located in the 'webpages' folder on your web server, you could use the following bit of code:
$contentsFile="webpages/contentsFile.txt"; ...and that's it! One possible problem is that by default you will probably not be able to write to files on your web server without changing the permissions on the folder where you want to write the file. For information on how to resolve this issue, go to Using PHP to Change the Permissions on a Folder. Go back to PHP Tutorials home page Go back to Tutorials home page
|