..
File_put_contents function is used to write in a file. Its use is equivalent to using concatenated functions fopen , fwrite , and fclose .
The function file_put_contents provides 4 parameters, the first two (mandatory) is the reference to the file and to write data to write.
If the file does not exist it is created, if there is a pointer is set - by default - in the beginning, and any content is clipped.
The function returns, if successful, the number of bytes written, otherwise an error.
Here's an example:
<? Php
$ Content = 'Hurray TOPlist
Here you will learn PHP! ';
file_put_contents ('/ folder / sample.txt', $ content);
?>
If you want to add the new content that may be already on file will be enough to specify, as the third parameter, the flag FILE_APPEND this:
<? Php
$ Content = 'Hurray TOPlist
Here you will learn PHP! ';
file_put_contents ('/ folder / sample.txt', $ content, FILE_APPEND);
?>
| |
Linux (Course)
Complete guide to open-source system. From 49 €. |
| |
MySQL (Course)
Management of open-source database. From 39 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |