PHP file_put_contents () functions (integrated with fopen, Fwrite, fclose) _php Tutorials

Source: Internet
Author: User
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 ...

  • 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.