victorianrider Posted March 30, 2011 Share Posted March 30, 2011 Hey guys, I have a script that is run once a week to fetch some user info for a large number of accounts. The code I have now writes the info correctly, but I was wondering if there was an easy way to have the accountdata.txt file completely wiped before new updated info is written to it, as opposed to deleting it manually every week. $FileName = "accountdata.txt"; $f=fopen($FileName,"a+"); fwrite($f, $UserKey[$i]." ".$SigKey[$i]."\n"); $f=fclose; I could in theory just open the file and delete everything in it manually, save it and then run this script, but I'm always looking for more ways to make things efficient, and come a time when it's run more than once a week it'd be nice to have all that automated. So in summary, I need it to delete all data (if any) from the accountdata.txt file before it writes anything to it. Thanks. Link to comment https://forums.phpfreaks.com/topic/232142-fopen-fwrite-and-fclose-help-with-a-text-file/ Share on other sites More sharing options...
gizmola Posted March 30, 2011 Share Posted March 30, 2011 There's a very simple php function named unlink. Link to comment https://forums.phpfreaks.com/topic/232142-fopen-fwrite-and-fclose-help-with-a-text-file/#findComment-1194154 Share on other sites More sharing options...
gizmola Posted March 30, 2011 Share Posted March 30, 2011 If you want this all in one script, you could add a little code that finds the day of the week based on date, so if you want this to be done let's say on Sunday only, something like: if (date('N') == 7) unlink($FileName); Link to comment https://forums.phpfreaks.com/topic/232142-fopen-fwrite-and-fclose-help-with-a-text-file/#findComment-1194155 Share on other sites More sharing options...
victorianrider Posted March 30, 2011 Author Share Posted March 30, 2011 If you want this all in one script, you could add a little code that finds the day of the week based on date, so if you want this to be done let's say on Sunday only, something like: if (date('N') == 7) unlink($FileName); Thankyou very much Link to comment https://forums.phpfreaks.com/topic/232142-fopen-fwrite-and-fclose-help-with-a-text-file/#findComment-1194210 Share on other sites More sharing options...
victorianrider Posted March 30, 2011 Author Share Posted March 30, 2011 Hmm, I'm not seeing the Mark As Solved button, so I'll just state that it is solved Link to comment https://forums.phpfreaks.com/topic/232142-fopen-fwrite-and-fclose-help-with-a-text-file/#findComment-1194214 Share on other sites More sharing options...
gizmola Posted March 30, 2011 Share Posted March 30, 2011 No worries, the solved mod has gone awol. We all long for its return Link to comment https://forums.phpfreaks.com/topic/232142-fopen-fwrite-and-fclose-help-with-a-text-file/#findComment-1194224 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.