note 46364 added to function.file-put-contents
| From: | rehfeld dot us at osu1 dot php dot net | Date: | Fri, 08 Oct 2004 10:19:17 +0000 |
| Subject: | note 46364 added to function.file-put-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78176@lists.php.net to get a copy of this message | ||
<?php
/*
This is a nice function to save code and time.
Default is like calling fopen() in 'w' mode
To append to a file(like calling fopen() in 'a' mode), you add the Constant
FILE_APPEND
as a flag
please note this returns the bytes written,
or boolean false on error. So its wise to check the result using the === operator to specifically
check for false.
Otherwise, if for some reason you successfully write 0 bytes, you might misinterpret it as a failure
*/
$filename = 'filename.txt';
$data = 'Some text';
// this is like fopen() in 'w' mode
$bytes = file_put_contents($filename, $data);
// this is like fopen() in 'a' mode
$bytes = file_put_contents($filename, $data, FILE_APPEND);
if (false !== $bytes) {
echo "Wrote $bytes bytes to $filename\n";
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.file-put-contents.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46364
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46364&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46364&report=yes
Search -- http://master.php.net/manage/user-notes.php