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/wenjian/fs1473.html
转载随意^^请带上本文地址!