note 32819 deleted from function.file-put-contents by didou

From: Date: Mon, 02 Feb 2004 14:34:04 +0000
Subject: note 32819 deleted from function.file-put-contents by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64553@lists.php.net to get a copy of this message
Note Submitter: kevin@oceania.net ---- This simple example shows how to use file_put_contents() to append text to the bottom of a file. <?php // just so we know it is broken error_reporting(E_ALL); // specify a filename $filename = 'myfile.txt'; // text to append to the file (note the newline) $text = 'This is some text to add'."\n"; // check to see if the file exists and is writable if(is_writable($filename)) { // write the file myfile.txt if(!@file_put_contents($filename, $text, FILE_APPEND)) { // if we are unable to write for any reason echo "Unable to write to file $filename"; } else { // give praise to the php gods echo "Success writing to $filename"; } } else { // if the file does not exist or is not writable.. echo "The file $filename does not exist or is not writable"; } ?>

« previous php.notes (#64553) next »