时间:2021-07-01 10:21:17 帮助过:4人阅读
$fn = 'filename';
$fp = fopen($fn, 'r+');
$size = filesize($fn);
$offs = 0;
$n = 0;
while($buf = fgets($fp)) {
$n++;
if($n == N) break;
$offs = ftell($fp);
}
$thru = fread(fp, $size);
$buf = '..' . substr($buf, 6);
fseek($fp, $offs);
fwrite($fp, "$buf\n$tfrh");
ftruncate($fp);
fclose($fp);
11111111
2222222
33333333
44444444
55555555
66666666
77777http://p7.game.com/pic.png777
888888888
99999999999
$line = 7;
$search = 'http://p7.game.com/pic.png';
$replace = '../images/pic.png';
$content = file_get_contents('test.txt');
$data = explode(chr(10), $content);
if(isset($data[$line-1])){
$data[$line-1] = str_replace($search, $replace, $data[$line-1]);
file_put_contents('test.txt', implode(chr(10), $data));
}