skip to Main Content
How To Write The Text File Using PHP

How to write the text file using PHP

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.

 

Saroj

I am a web designer and developer part-time blogger. Write something on some free time. Find my every day thought here :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top