hi all, I have a message board that is reading (and writing to) from a .html file using a PHP include. I have seen it used on another site so I know its possible, but I need a script or piece of code that clears the file monthly. thanks all =]
Problem with that code is that, if it's executed on "landing page", the file will be wiped multiple times (probably alot of times depends on much traffic you get), you need to make sure it is only ran once on that day. And if the file was not accessed on that day, then the file won't be wiped at all.
Hmm.. how about deciding on how many message you want to keep, rather then deleting a whole month of messages. For example lets say you decided to keep the last 200 messages, when you reach that amount you could implement something like this, which will delete the oldest message each time it runs, so you would place this code after your insert / write code, in-turn a new message goes in and the oldest message gets deleted out, of course this is based on line by line and it is a txt file we are talking about right ? <?php $path = 'file.txt'; $line = file($path); foreach ($line as $key => $value) { if ($key <= 0) {unset($line[$key]);} else {break;} } $line = implode("", $line); $handle = fopen($path, 'w'); $size = fwrite($handle, $line); ?> PHP: