Complete PHP Filesystem Reference
The file_put_contents() writes a string to a file.
This function follows these rules when accessing a file:
This function returns the number of character written into the file on success, or FALSE on failure.
| Parameter | Description |
|---|---|
| file | Required. Specifies the file to write to. If the file does not exist, this function will create one |
| data | Required. The data to write to the file. Can be a string, an array or a data stream |
| mode | Optional. Specifies how to open/write to the file. Possible
values:
|
| context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream. |
Note: Use FILE_APPEND to avoid deleting the existing content of the file.
The output of the code above will be:
Complete PHP Filesystem Reference
Your message has been sent to W3Schools.