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().
1 2 3 4 5 6 7 8 9 10 11 |
<?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…
Click on title to read the entire article