note 32845 added to function.file-put-contents

From: Date: Sun, 08 Jun 2003 23:20:47 +0000
Subject: note 32845 added to function.file-put-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-50006@lists.php.net to get a copy of this message
As there is no FILE_PREPEND for this function, here is an example of how you can write to the top of a file using file_put_contents(). Note: you must have permission to read and write to the file. <?php // just so we know it is broken error_reporting(E_ALL); // our file name $filename = 'myfile.txt'; // string to prepend to the file $text = 'This line goes at the top of the file'."\n"; // write the file contents into a buffer $buff = file_get_contents($filename); // write the new line and the buffer to the file if(!@file_put_contents($filename, $text.$buff)){ echo "Unable to write to file $filename"; }else{ // Give praise and thanks to the php gods echo "Success writing to $filename"; } ?> ---- 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+32845 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32845&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32845&report=yes

« previous php.notes (#50006) next »