php读取文本文件替换指定行
如果让你大家操作数据库替换内容非常的简单,但是txt文件要如何操作呢,下面我来给大家分享了个替换实例。
$file_path = '123.txt'; $content = file_get_contents($file_path); //按换行符把全部内容分隔成数组 $con_array = explode("n", $content); //替换掉指定行 $con_array[12]="123"; //组合回字符串 $con = implode("n", $con_array); //写回文档 file_put_contents($file_path, $con);
本文地址:http://www.phprm.com/base/57067.html
转载随意,但请附上文章地址:-)