Home » , » Append a String to a File Using PHP

Append a String to a File Using PHP

Written By Unknown on Jumat, 07 Mei 2010 | 01.15

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...!!");
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger