PHP Write To File

This script will allow you to Write to a file named text.txt

r Read only. Pointer set at top of file data.
r+ Read and write. Pointer set at top of file data.
w Write only. Any existing data will be deleted. If file is not found, PHP will create one.
w+ Read and write. Any existing data will be deleted. If file is not found, PHP will create one.
a Appending only. New data will be written at the end of the existing file data.
a+ Read and appending. New data will be written at the end of the existing file data.

 

Remember to change the file name text.txt to any file name of your choice.

Note: You will also need to set write permission on the folder where text.txt will be stored

 

Script Source

<?php
$myFile = "text.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData);
$stringData = "Tracy Tanner\n";
fwrite($fh, $stringData);
fclose($fh);
?>

 

Please let me know if this script was helpful to you.

[rating]