当前位置:网站首页>PHP fopen write file content
PHP fopen write file content
2022-08-06 11:54:00 【Mo Xiao】
php can write or append data to the file through fopen or file_put_contents. Let me introduce the fopen method:
The fopen() function opens a file or URL. If the opening fails, this function returns FALSE.
I. Grammar:
Syntax: fopen(filename,mode,include_path,context)
filename Required.Specifies the file or URL to open.mode Required.Specifies the type of access required to this file/stream.Possible values are shown in the table below.include_path is optional.This parameter can be set to 1 or TRUE if the file needs to be retrieved in include_path as well.context is optional.Specifies the environment for the file handle.Context is a set of options that can modify the behavior of the stream.Possible values for the mode parameter: "r", "r+", "w", "w+", "a", "a+", "x", "x+"
“r”: Open in read-only mode, and point the file pointer to the file header."r+": Open for reading and writing, and point the file pointer to the file header."w": Open for writing, point the file pointer to the file header and truncate the file size to zero.if the document does not exist, try to create it."w+": Open for reading and writing, point the file pointer to the file header and truncate the file size to zero.if the document does not exist, try to create it."a": Open for writing, point the file pointer to the end of the file.if the document does not exist, try to create it."a+": Open for reading and writing, and point the file pointer to the end of the file.if the document does not exist, try to create it."x": Create and open for writing, pointing the file pointer to the file header.If the file already exists, the fopen() call fails and returns FALSE with an E_WARNING level error message.if the document does not exist, try to create it."x+": Create and open for read-write, pointing the file pointer to the file header.If the file already exists, the fopen() call fails and returns FALSE with an E_WARNING level error message.if the document does not exist, try to create it.Write content as appends
$fp = fopen('test.txt','a');//fwrite($fp, 'I am appending the content'.PHP_EOL);//PHP_EOL newlinefclose($fp);边栏推荐
猜你喜欢
随机推荐
聊聊动态代理IP
The vant component van-dropdown-menu covers the list page in the applet, causing the bindtap click event to fail from time to time
Kubernetes DevOps 工具
ES6 new feature - generator
Notion Chinese: client, web-side localization solution
MySQL statistics are not allowed to cause performance problems
电脑死机是什么原因 怎样避免这个问题?
纯色山鹪莺
在常州“超级虚拟工厂”,中国智造正在“原力觉醒”
RedTiger‘s Hackit -- level 10
Kubernetes 集群故障案例
Kubernetes 开源未来
自动化测试是什么?应用在哪儿?
LeetCode_50_Pow(x,n)
NC2 重排链表
美创科技8个医疗数据安全场景化方案推出!
工作之余想线上学习软件测试靠谱么?
#yyds干货盘点#range() 函数
用代码画时序图!YYDS
P1747 What a strange game









![[SQL brush questions] Day2----SQL syntax basic query](/img/6b/d3eb1fe4055b9919be83d43e3e5af7.png)