fputs()出现错误怎么处理怎么解决

fputs()出现错误怎么处理怎么解决,第1张

fopen("00","w")

注意这里的第二个参数W,

意思是:Opens an empty file for writing. If the given file exists, its contents are destroyed

翻译过来就是:打开一个空文件写,如果指定的文件存在,文件的内容会被摧毁

明白了么?

每次循环都从文件开头写一个字符,重复覆盖.把w改成a就可以了应该

下面是第二个参数的常用森老VALUE

The character string mode specifies the type of access requested for the file, as follows:

"r"

Opens for reading. If the file does not exist or cannot be found, the fopen call fails.

"w"

Opens an empty file for writing. If the given file exists, its contents are destroyed.

"滑春樱a"

Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the filecreates the file first if it doesn’信丛t exist.

"r+"

Opens for both reading and writing. (The file must exist.)

"w+"

Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.

"a+"

Opens for reading and appendingthe appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is completecreates the file first if it doesn’t exist.

不是这个得看你打开文件的时候是以什么方式打开孝咐的了

fopen("你要打开的巧此纯文件","打开方式")

打开方式:

注意 只要是带有"a"的都是追加 如"a+"就扒哪是为读写打开文件追加末尾

你写成"r+","w+"就行了

以a方式打开文件可以在文件的末尾写入内容,例如下面的代码在文件的a.txt的末尾添加123:

<?php

    $fp=fopem("a.txt","a")

    fputs($fp,"123")

    fclose($fp)

?>

其它打开方式的说明:

'r'    只读方式打开,将文件指针指向文件头。         

'r+'    读写方式打开,将文件指针指向文件头。         

'w'    写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。         

'w+'    读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不扰简空存在则尝试咐闹创建之。         

'a'    写入方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。         

'a+'    读写方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。         

'x'    创建并以写入方式打开,将文件指针指向文件头。如果文件已存在,则        fopen() 调用失败并返回 FALSE,并生成一条        E_WARNING 级别的错误信息。如果文件不存在则尝试创建之。这和给        底层缓瞎的 open(2) 系统调用指定        O_EXCL|O_CREAT 标记是等价的。此选项被         PHP 4.3.2 以及以后的版本所支持,仅能用于本地文件。         

'x+'    创建并以读写方式打开,将文件指针指向文件头。如果文件已存在,则        fopen() 调用失败并返回 FALSE,并生成一条        E_WARNING 级别的错误信息。如果文件不存在则尝试创建之。这和给        底层的 open(2) 系统调用指定        O_EXCL|O_CREAT 标记是等价的。此选项被        PHP 4.3.2 以及以后的版本所支持,仅能用于本地文件。         


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/12281315.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存