note 33236 added to function.file-put-contents
| From: | me at crazy dot net | Date: | Thu, 19 Jun 2003 19:33:31 +0000 |
| Subject: | note 33236 added to function.file-put-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50677@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+33236
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33236&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33236&report=yes