时间:2010-07-26 04:48:02

标签: php file

6 个答案:

答案 0 :(得分:23)

答案 1 :(得分:14)

答案 2 :(得分:4)

$filename  = "log.txt";
$file_to_read = @fopen($filename, "r");
$old_text = @fread($file_to_read, 1024); // max 1024
@fclose(file_to_read);
$file_to_write = fopen($filename, "w");
fwrite($file_to_write, "new text".$old_text);

答案 3 :(得分:0)

答案 4 :(得分:-1)

答案 5 :(得分:-3)

            $file = fopen('filepath.txt', 'r+') or die('Error');
            $txt = "/n".$string;
            fwrite($file, $txt);
            fclose($file);

这将在文本文件中添加一个空行,因此下次写入时会替换空白行。用空行和你的字符串。

这是唯一且最好的技巧。