PHP追加文件

可以通过在fopen()函数中使用aa+模式将数据追加到文件中。 下面来看看一个简单的例子,将数据附加(追加)到data.txt文件中。

让我们先看看文件(data.txt)中的数据。

welcome to php file write

PHP附加到文件 - fwrite()函数

PHP fwrite()函数用于将数据写入和追加到文件中。

示例

<?php  
$fp = fopen('data.txt', 'a');//opens file in append mode  
fwrite($fp, ' this is additional text ');  
fwrite($fp, 'appending data');  
fclose($fp);  

echo "File appended successfully";  
?>

执行上面代码输出结果(查看data.txt文件中的内容)如下 -

welcome to php file write this is additional text appending data

上一篇: PHP删除文件 下一篇: PHP上传文件