Page 1 of 1

Delete the contents of a txt file

Posted: Tue Oct 22, 2002 9:04 pm
by sinewave
I understand how to open and read the contents of a text file using fopen() but i am looking to find a way to clear out the txt file, or at least delete it and make a new one with nothing in it.

i have a text field that will just append the entered text to the end of the old text, i want it to overwrite it.

Any advice?

Posted: Tue Oct 22, 2002 9:14 pm
by volka
http://www.php.net/manual/en/function.fopen.php[quote]...
mode specifies the type of access you require to the stream. It may be any of the following:
...
'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.[/quote]

Posted: Tue Oct 22, 2002 9:15 pm
by sinewave
thanks!

Posted: Tue Oct 22, 2002 9:46 pm
by sav

Code: Select all

$fp = fopen('file.txt, 'w');
fwrite($fp, '');
8)