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