Command: file_put_contents();
Command analysis: file_put_contents (PHP 5)
file_put_contents -- Write a string to a file
Instructions:
int file_put_contents ( string filename, string data [, int flags [, resource context]] )
It has the same function as calling fopen(), fwrite() and fclose() in sequence.
The data parameter can be an array (but not a multi-dimensional array), which is equivalent to file_put_contents($filename, join('', $array))
Since PHP 5.1.0, the data parameter can also be specified as a stream resource. The cached data saved in the stream will be written to the specified file. This usage is similar to using the stream_copy_to_stream() function.
Parameter
filename
The name of the file to which data will be written.
data
Data to be written. The type can be string, array or stream resource (as mentioned above).
flags
flags can be FILE_USE_INCLUDE_PATH, FILE_APPEND and/or LOCK_EX (to obtain an exclusive lock), however use FILE_USE_INCLUDE_PATH with extreme caution.
context
A context resource.
Write the code (the code itself is correct, but I learned another function of it by mistake):
Copy the code The code is as follows:
$contents = "This is using The content written by file_put_contents";
$contents2 = array("This is the content written using ","file_put_contents","The content written by the command");
file_put_contents("html/caceh.txt",$contents);
file_put_contents( "html/cache2.txt",$contents2);
?>
The above has introduced the php file_put_contents function (integrated fopen, fwrite, fclose), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.