相同点:file_put_contents() 函数把一个字符串写入文件中,与依次调用 fopen(),fwrite() 以及 fclose() 功能一样。
不同点:在file_put_contents()函数中使用 FILE_APPEND 可避免删除文件中已有的内容,即实现多次写入同一个文件时的追加功能。
例如:
echo file_put_contents("test.txt","Hello World. Testing!",FILE_APPEND);
file_put_contents是以追加的形式将字符串写入到test.txt中,
fwrtie则是会清除之前的记录,只保留当前写入的内容
立即学习“PHP免费学习笔记(深入)”;
$file = fopen("test.txt","w"); echo fwrite($file,"Hello World. Testing!"); fclose($file);
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号