【发布时间】:2017-09-23 20:43:45
【问题描述】:
当我使用此代码时
$fp = fopen('data.txt', 'w');
fwrite($fp, $data);
fclose($fp);
它会覆盖文本。我也想要页脚的旧数据。那么,如何在不删除 PHP 的情况下将新数据添加到 .txt 的顶部
可能的 output.txt 和视图
(new) line8
(new) line7
(new) line6
(old) line5
(old) line4
(old) line3
(old) line2
(old) line1
【问题讨论】:
-
您可以随时读取数据并连接到 $data 不是吗? :|
-
文件变大时会很痛苦
-
@marmeladze 任何解决方案,如果尺寸更大
-
<?php $cmd1 = "echo 'Lorem ipsum' > some.txt"; $cmd2 = "cat some.txt big.txt > new.txt";shell_exec($cmd1);shell_exec($cmd2); ?>-)))