PHP MySQL Tutorial
Learn PHP and MySQL

Append a String to a File Using PHP

100% of people found this useful
Append a String to a File Using PHP

To append a string to a file you will need to open the file using fopen() with the 'a' parameter. For example if your log file name is mylog.txt you would write the code like this :

// open the log file and check if the it's opened successfully
if (!($fp = fopen('mylog.txt', 'a'))) {
   die('Cannot open log file');
}

// ... your code do something here

// append to log file
// make sure you add a newline character at the end of the log string
fwrite($fp, "Initiate world domination\n");

// ... do some stuff here

// ... and your code do something else here

// append another line to the log file
fwrite($fp, "World domination completed. Bwa ha ha ha...!!");

Recent Comments

By: mdfirdosh92 Posted on 07-09-2015 10:13 AM

Wish you a <a href="happynewyears.in/">Happy New Year </a>  and <a href="happydiwalifestival.com/">Happy Diwali </a>  to everyone. Send special New Year SMS and diwali sms to all your friends.

By: jenefee Posted on 07-11-2015 12:11 AM

Thanks for the data, perhaps I will use this all over my tufted selling and i have been use much ring American statedia in run a interaction and that they somebody existing a giant amend on me. http://www.pbsbobet.com/

Powered by Community Server (Non-Commercial Edition), by Telligent Systems