PHP教程
PHP Mysql
PHP面向对象
PHP常用

PHP 附加到文件

PHP 附加到文件

您可以在 fopen() 函数中使用 a 或 a+ 模式将数据附加到文件中。看一个简单的例子,将数据追加到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
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4