PHP file_put_contents () function (integrated fopen, Fwrite, fclose) _php tips

Source: Internet
Author: User
Command: File_put_contents ();
Command resolution: File_put_contents (PHP 5)
File_put_contents-Writes a string to a file
Description
int file_put_contents (string filename, string data [, int flags [, resource context]])

and call fopen (), fwrite () and fclose () in turn.
Parameter data can be an array (but not a multidimensional 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, where the stored cache is written to the specified file, similar to the use of the Stream_copy_to_stream () function.
Parameters

FileName
The name of the file to be written to.
Data
The data to write. Types can be String,array or stream resources (as described above).
Flags
Flags can be file_use_include_path,file_append and/or LOCK_EX (get an exclusive lock), but use File_use_include_path with special care.
Context
A context resource.
Write code (the code itself is infallible, but has learned another feature of it):
Copy Code code as follows:

<?php
$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 write a string to the Cache.txt,cache2.txt two files using the file_put_contents command.
Results: New caceh.txt files are added to the HTML file directory, you know ————
Remember: the file_put_contents () function integrates fopen (), fwrite (), fclose () Three functions, in this case the new file is the function of fopen ().

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.