Command: file_put_contents ();
Command Parsing: file_put_contents (PHP 5)
File_put_contents -- write a string to a file
Note:
Int file_put_contents (string filename, string data [, int flags [, resource context])
It is the same as calling the fopen (), fwrite (), and fclose () functions in turn.
The parameter data 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 stored in stream will be written to the specified file. This usage is similar to stream_copy_to_stream () function.
Parameters
Filename
The name of the file to be written.
Data
The data to be written. The type can be string, array, or stream resources (as mentioned above ).
Flags
Flags can be FILE_USE_INCLUDE_PATH, FILE_APPEND and/or LOCK_EX (get an exclusive lock). However, be cautious when using FILE_USE_INCLUDE_PATH.
Context
A context resource.
Write code (the Code itself is error-free, but has learned another feature ):
Copy codeThe Code is as follows:
<? Php
$ Contents = "this is the content written using file_put_contents ";
$ Contents2 = array ("this is used", "file_put_contents", "command written content ");
File_put_contents ("html/caceh.txt", $ contents );
File_put_contents ("html/cache2.txt", $ contents2 );
?>
Code Analysis: computation uses the file_put_contentscommand to write strings to cache.txt and cache2.txt files.
Result: The caceh.txt file is added to the HTML directory ----
Note: The file_put_contents () function integrates the fopen (), fwrite (), and fclose () functions. The new file in this example is the function of fopen.