Erase all data from a txt file - php

Possible duplicate:
How to clear text file contents in php

Hi..

How to erase all saved data (empty) in the text file myfile.txt using php ??

+6
source share
6 answers
 $handle = fopen ("/path/to/file.txt", "w+"); fclose($handle); 

See additional documentation.

+8
source

PHP file_put_contents() should be useful in this case. Here is a sample code:

 file_put_contents('myfile.txt', ''); 
+10
source
 <?php file_put_contents("myfile.txt", ""); ?> 
+4
source
 $file = fopen('myfile.txt', 'w'); fclose($file); 
+2
source
 $handle = fopen("myfile.txt", "w+"); fwrite($handle , ''); fclose($handle); 
0
source
 $myFile = "myFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, ""); fclose($fh); 
0
source

Source: https://habr.com/ru/post/885828/


All Articles