note 32819 added to function.file-put-contents

From: Date: Sun, 08 Jun 2003 04:37:04 +0000
Subject: note 32819 added to function.file-put-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-49963@lists.php.net to get a copy of this message
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"; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.file-put-contents.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32819 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32819&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32819&report=yes

« previous php.notes (#49963) next »