Home > Backend Development > PHP Tutorial > php file_put_contents()函数

php file_put_contents()函数

WBOY
Release: 2016-05-19 12:15:10
Original
1185 people have browsed it

 Definition and Usage  定义和用法

The file_put_contents() writes a string to a file.
file_put_contents()函数的作用是:将一个字符串写入文件。
This function follows these rules when accessing a file:  当访问一个文件是,函数必须遵循下面这些法则:
  1. If FILE_USE_INCLUDE_PATH is set, check the include path for a copy of *filename* 
    如果设置了FILE_USE_INCLUDE_PATH,那么将检查*filename*副本的内置路径
  2. Create the file if it does not exist 
    如果文件不存在,将创建一个文件
  3. Open the file 
    打开文件
  4. Lock the file if LOCK_EX is set 
    如果设置了LOCK_EX,那将对文件上锁
  5. If FILE_APPEND is set, move to the end of the file. Otherwise, clear the file content 
    如果设置了FILE_APPEND,那么将移至文件末尾;否则的话,将会清除文件的内容
  6. Write the data into the file 
    向文件中写入数据
  7. Close the file and release any locks 
    关闭文件并对所有文件解锁
This function returns the number of character written into the file on success, or FALSE on failure.
如果函数运行成功,将返回写入文件中的字符数量;如果失败,则返回False。
Syntax
语法
file_put_contents(file,data,mode,context)
Parameter
参数
Description
描述
file Required. Specifies the file to write to. If the file does not exist, this function will create one 
必要参数。指定写入文件对象。如果该文件不存在,函数将自动创建该文件
data Required. The data to write to the file. Can be a string, an array or a data stream
必要参数。指定写入文件的数据,可以使一个字符串或者是一个数组
mode Optional. Specifies how to open/write to the file. Possible values:
可选参数。指定打开/书写文件的方法:
  • FILE_USE_INCLUDE_PATH
  • FILE_APPEND
  • LOCK_EX
context Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream.
可选参数。指定需要进行处理的文件context[内容]。Context是一组选项,你可以通过它修改你的文本属性
1 2  下一页
Related labels:
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