hey everyone...so here is what i'm trying to do. I plan to setup a cron job which will run once every night. The cron will call a PHP file that should count the number of lines in a text file. Once the number of lines reaches X (for example, 75) it would then either remove the text file and recreate it - or just wipe the file clean and remove all 75 lines. I'm not too good with PHP programming but I did find some code to count the number of lines. What i'm having problems with now would be the if statement that remove the file or the lines...Any help or links to a good tutorial would be nice!
I wouldn't know how to do this via a cron command. I was thinking there are probably more people out there who would know how to do this via PHP as opposed to a one-line command.
You just need to open the file, get the contents http://www.php.net//manual/en/function.file-get-contents.php explode the contents into an array $bits = explode("\n", $contents); check the size of the array if (count($bits) > 75) {} unlink the file to delete create the new empty file but... what is the role of the file? why does it only get checked once a day? without knowing what you are actually trying to do I'd recommend using a table in a database and then just selecting from the database based on the date and whatever other criteria exist with a limit of x (ie 75). Then once in a blue moon you can pop in and delete the old records from the table.
Thanks for your help sarahk, but I think I figured it out. First, open and count the lines $file="/path/to/your/file";$linecount = 0;$handle = fopen($file, "r"); while(!feof($handle)){$line = fgets($handle);$linecount++; }fclose($handle); Code (markup): Then, determine if it's 75 lines and wipe: if($linecount >= 75) {$fh = fopen($file, 'w') or die("can't open file");fwrite($fh, "");fclose($fh); } Code (markup): Thanks..