Delete the contents of a txt file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sinewave
Forum Commoner
Posts: 41
Joined: Tue Sep 10, 2002 4:35 pm
Location: Canada

Delete the contents of a txt file

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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]
sinewave
Forum Commoner
Posts: 41
Joined: Tue Sep 10, 2002 4:35 pm
Location: Canada

Post by sinewave »

thanks!
sav
Forum Newbie
Posts: 8
Joined: Mon Oct 21, 2002 7:29 pm

Post by sav »

Code: Select all

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