问题描述:

i have a php file A.php.Every time my page A.php is called i want it to write some data to a file.

I want to appent to a existing file and not overwrite

how do i do this

网友答案:

The easiest is to use the file_put_contents function with the FILE_APPEND flag:

file_put_contents('filename', 'data', FILE_APPEND);
网友答案:

To write to file b.txt (for example) use this:

<?php
$fp = fopen('b.txt', 'a');
fwrite($fp, '1');
fclose($fp);

That will write "1" to b.txt every time you run it.

网友答案:

This tutorial should get you going

$myFile = "testFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "String 1\n";
fwrite($fh, $stringData);
$stringData = "String 2\n";
fwrite($fh, $stringData);
fclose($fh);
相关阅读:
Top