hello again lol.
i have a simple news script, and its just perfect, ive made it for somebody who dosent know much and they have their own form to add news, the news goes into a .txt file and its exported to a certain part of his page.
what i want to do is add a link or button to empty that file, so that when his little news section gets full, he just hits delete and it emptys that file ready for more news.
is there a function or something for this? i had a look on php.net but nothing i can see there.
thanks.
Emptying a text file?
Moderator: General Moderators
- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
I believe this should work:
Opening a file with the 'w' option will truncate the file to zero length and place the pointer at the beginning of the file.
Code: Select all
<?php
$filepath = '/path/to/file.txt';
$fres = fopen($filepath, 'w');
fclose($fres);
?>thanks for that, just another question though, how do i execute that lol, sorry, im super new at this
, im slowly learning though 
would i wrap it in my own function? then use something to execute the function?
i want it so he just clicks something like a "empty news" link and it magically emptys the file
thanks
would i wrap it in my own function? then use something to execute the function?
i want it so he just clicks something like a "empty news" link and it magically emptys the file
thanks