php写入文件的方法有哪些

avatar
作者
筋斗云
阅读量:0

  1. 使用file_put_contents函数
$file = 'file.txt'; $content = 'Hello, world!'; file_put_contents($file, $content); 
  1. 使用fopen、fwrite和fclose函数
$file = 'file.txt'; $content = 'Hello, world!'; $handle = fopen($file, 'w'); fwrite($handle, $content); fclose($handle); 
  1. 使用file_put_contents函数并添加追加模式
$file = 'file.txt'; $content = 'Hello, world!'; file_put_contents($file, $content, FILE_APPEND); 
  1. 使用fopen函数打开文件,然后使用fwrite函数写入内容
$file = 'file.txt'; $content = 'Hello, world!'; $handle = fopen($file, 'a'); fwrite($handle, $content); fclose($handle); 
  1. 使用file_put_contents函数并设置其他参数,如权限等
$file = 'file.txt'; $content = 'Hello, world!'; file_put_contents($file, $content, LOCK_EX); 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!