PHP Tutorial : Write to a file with fwrite
Jun 11, 2009 Basic PHP
I showed you earlier in a older post how to open and read text contents from a file. Now it’s time to see how to write to a file using php function called fwrite().
<?php $theFileToWriteTo = "textFile.txt"; $fileHandle = fopen($theFileToWriteTo, 'w') or die("cannot open the text file"); $textToWrite = "First text to write here\n"; fwrite($fileHandle, $textToWrite); $textToWrite = "Second line to write here\n"; fwrite($fileHandle, $textToWrite); fclose($fileHandle) ?>
Note that “\n” means new line!
Tags: file handle, fwrite, php file handle, php fwrite, php write to a file


June 11th, 2009 at 1:08 am
[...] This post was Twitted by freephptutorial – Real-url.org [...]