php file_put_contents() function (integrated fopen, fwrite, fclose)_PHP tutorial

WBOY
Release: 2016-07-21 15:29:03
Original
1207 people have browsed it

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]] )

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 For stream resources, the cache data saved in the stream will be written to the specified file. This usage is similar to using the stream_copy_to_stream() function.
Parameters

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 it learned another function by mistake):

Copy the code The code is as follows:

$contents = "This is the content written using file_put_contents";
$contents2 = array("This is written using the ","file_put_contents"," command
file_put_contents("html/caceh.txt",$contents);
file_put_contents("html/cache2.txt",$contents2);
?>

Code analysis: Plan to use the file_put_contents command to write strings to the two files cache.txt and cache2.txt.
Result: The caceh.txt file was added in the html file directory, you understand————
Remember: the file_put_contents() function integrates fopen(), fwrite(), and fclose() A function. In this example, the newly created file is the function of fopen().

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323497.htmlTechArticleCommand: file_put_contents(); Command analysis: file_put_contents (PHP 5) file_put_contents -- Write a string to a file Description: int file_put_contents ( string filename, s...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template