Jump to content

fopen, fwrite and fclose help with a text file


victorianrider

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.