PHP file_put_contents function

Source: Internet
Author: User

The file_put_contents () function writes a string to the file and calls fopen (), fwrite (), and fclose () in turn.

Description
Parameter data can be an array (but not a multidimensional array).

From PHP 5.1.0, the data parameter can also be specified as a stream resource, and the cached data stored in the stream will be written to the specified file, similar to the use of the Stream_copy_to_stream () function.

Support for the context parameter is added by the PHP 5.0.0.

return value
The function returns the number of bytes written to the data in the file.


Grammar
File_put_contents (File,data,mode,context)

File required. A file that requires data to be written. If the file does not exist, a new file is created.
Data is optional. Specify the data to be written to the file. Can be a string, array, or data stream.
mode is optional. Specify how to open/write files. Possible values:

File_use_include_path
File_append
Lock_ex

The context is optional. The environment that prescribes the file handle.

The context is a set of options that can modify the behavior of a stream. If NULL is used, it is ignored.

*/

$str = ' original article of this site turn please note from Www.111cn.net ';
$file = ' 111cn.net.txt ';

 
 if (file_put_contents ($file, $str))
 {
  echo file_get_contents ($file);
&NBSP}
 else
 {
  echo $file, ' cannot create please check permission ';
 }
 
 
&NBSP
 //This article original in Www.111cn.net reprint indicates the Origin
"

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.