note 46364 rejected from function.file-put-contents by tularis
| From: | tularis@php.net | Date: | Fri, 08 Oct 2004 11:59:50 +0000 |
| Subject: | note 46364 rejected from function.file-put-contents by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78178@lists.php.net to get a copy of this message | ||
Note Submitter: rehfeld.us
----
<?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";
}
?>