php bir metin dosyasına yazma [kapalı]

3 Cevap

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

ben bunu nasıl yapabilirim

3 Cevap

Kolay file_put_contents function with the FILE_APPEND bayrağı kullanmak için:

file_put_contents('filename', 'data', FILE_APPEND);

B.txt dosyaya yazmak için (örneğin) bu kullanın:

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

Yani her çalıştırdığınızda b.txt için "1" yazacak.

Bu tutorial gidiyorsun almalısınız

$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);