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?
Delete the contents of a txt file
Moderator: General Moderators
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]
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]
Code: Select all
$fp = fopen('file.txt, 'w');
fwrite($fp, '');