Im working on a small project.
What Im trying to Do, is Have a PHP File, Delete Lines from a .txt file based on time
The .txt file will be formatted like this
Content | Time (Unix Time)
Content | Time (Unix Time)
Everytime the php file is executed i want it to delete everyline thats = or less than the current Time
Ive tried using google, and Have had no luck, I am pulling the time from one source. so that wont be a problem, Just the PHP Part.
Is there a snippet? or is this going to be difficult.
There are many ways to handle this… It is actually quite easy unless your file is really large. This method isn’t the most memory efficient, but it is probably the easiest.
Read the file into an array of lines with
file(), loop over them and explode each on|. Add the line to an output array if the timestamp is newer than the current time.In the end, write the file back out with the output array’s values:
Make sure
yourfile.txthas the appropriate write permissions for your web server user, or whatever user is executing this script.