Command: File_put_contents ();
Command parsing: file_put_contents (PHP 5)
File_put_contents--Writes a string to the file
Description
int file_put_contents (string filename, string data [, int flags [, resource context]])
and sequentially call fopen (), fwrite (), and the fclose () function.
Parameter data can be an array (but not a multidimensional array), which is equivalent to File_put_contents ($filename, Join (", $array))
From PHP 5.1.0, the data parameter can also be specified as a stream resource, where the cached data stored in stream is written to the specified file, which is similar to using the Stream_copy_to_stream () function.
Parameters
FileName
The name of the file to be written to.
Data
The data to write. The type can be a string,array or a stream resource (as mentioned above).
Flags
Flags can be file_use_include_path,file_append and/or LOCK_EX (get an exclusive lock), but be cautious when using File_use_include_path.
Context
A context resource.
Write the code (the code itself is error-free, but quirks learns another feature of it):
Copy CodeThe code is as follows:
$contents = "This is the content written using file_put_contents";
$contents 2 = Array ("This is used", "file_put_contents", "command-written content");
File_put_contents ("Html/caceh.txt", $contents);
File_put_contents ("Html/cache2.txt", $contents 2);
?>
Code Analysis: You intend to use the file_put_contents command to write a string to the Cache.txt,cache2.txt two files.
Result: A new Caceh.txt file has been added to the HTML file directory, do you understand ————
Remember: the file_put_contents () function integrates fopen (), fwrite (), fclose () three functions, and the newly created file in this example is the function of fopen ().
http://www.bkjia.com/PHPjc/323497.html www.bkjia.com true http://www.bkjia.com/PHPjc/323497.html techarticle command: file_put_contents (); command parsing: file_put_contents (PHP 5) File_put_contents-Writes a string to the file description: int file_put_contents (ST Ring filename, s ...