Definition :
The file_put_contents() writes data to a file.
This function follows these rules when accessing a file:
Note: Use FILE_APPEND to avoid deleting the existing content of the file.
file_put_contents(filename, data, mode, context)
Parameter | Description |
---|---|
filename | Required. Specifies the path to 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, 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. |
Given below example "demo.txt" file is empty and file_put_contents() is used to write data on "demo.txt" file:
Output : 18
"webdesigning house automatic reflected on dem.txt file"