This function writes a string to a file.

Syntax: file_put_contents(file,data,mode,context)

Description:

The Parameter “file” is Required. It Specifies the file to write to. If the file does not exist, this function will create one.

The second Parameter “data” is Required. The data to write to the file. Can be a string, an array or a data stream.

The third Parameter “mode” is Optional.It Specifies how to open/write to the file. Possible values:

FILE_USE_INCLUDE_PATH
FILE_APPEND
LOCK_EX

The third Parameter “context” is Optional. It Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream.

This function returns the number of character written into the file on success, or FALSE on failure.

Example:
Code:

echo file_put_contents("test.txt","Php code is executed on the server.");

Output:

35

eXTReMe Tracker