Home > Code Snippets > Write data to a text file
Write data to a text file
Description
This will open a plain text file (.txt) and save information to it.
The code
<?php
$your_data = "This is the data to be stored in the text file.";
// Open the file and erase the contents if any
$fp = fopen("textfile_name.txt", "w");
// Write the data to the file
fwrite($fp, $your_data);
// Close the file
fclose($fp);
?>
Get the code
Download the file to your computer: Click here to get the file
