How to write the text file using PHP. Many time we need to store some data to text file like we need to stored PHP log to the text file. So, let’s see how we can create the text file using PHP.
It’s too easy to create the new text file with content using PHP like.
$my_file = 'pathtotextfile.txt'; $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file); fwrite($handle, "First Line Text"); fwrite($handle, "Second Line Text"); fwrite($handle, "Third Line Text"); fclose($handle);
Just change the path where you want to store the text file.