How to write a file in PHP
To Open a new file for writing we can use
fopen($file_name,’w') Or we can use fopen($file_name,’a')
to append our content to existing file.
Three simple steps to write the content of a string to text file
1. Open the file in Write or append mode
$fp = fopen(”/path/save.txt”, “w”);
2. Use fwite command to write the string using above created file pointer
fwrite($fp,$string_to_be_written);
3.Close the file pointer
fclose($fp);
<?php
$string_to_be_written = 'File content to be written';
$fp = fopen("/path/save.txt", "w");
fwrite($fp,$string_to_be_written);
fclose($fp);
?>
