1、写文件
<?php //写文件 $file_path="text.txt"; if(!file_exists($file_path)){ echo "文件不存在"; exit(); } //"a+" 在文件后面追加 "w+"重新写入 $fp=fopen($file_path,"w+"); $con="\r\n你好"; for($i=0;$i<10;$i++){ fwrite($fp,$con);} echo "添加成功"; fclose($fp); ?>
2、第二中方式 通过file_put_contents函数
<?php //第二种方式写文件 $file_path="text.txt"; $content="hello,world\r\n"; //将一个字符串写入文件 默认是【FILE_USE_INCLUDE_PATH 】"w+"重新写入 file_put_contents($file_path,$content,FILE_APPEND); echo "OK"; ?>