Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:43:26+00:00 2026-06-09T23:43:26+00:00

Im working on a small project. What Im trying to Do, is Have a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:43:27+00:00Added an answer on June 9, 2026 at 11:43 pm

    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:

    $output = array();
    // Read the file into an array of lines:
    $lines = file('yourfile.txt');
    // Store the current time
    $now = time();
    
    foreach ($lines as $line) {
      // Split on |
      list($content, $time) = explode("|", $line);
      if ($time > $now) {
         // Keep the line in the output array:
         $output[] = $line;
      }
      // Otherwise do nothing with it
    }
    
    // Implode it back to a string and write to file:
    $outstring = implode("\n", $output);
    file_put_contents("yourfile.txt", $outstring);
    

    Make sure yourfile.txt has the appropriate write permissions for your web server user, or whatever user is executing this script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to use Linq to SQL for a small project I'm working on at
I am working on a small project for learning PHP better. This project has
I'm new to objective C and currently working on a small project. I have
I'm working on a small uni project where I have a program for a
I'm working on a small project trying to integrate lua with c++. My problem
I'm working on a small project and got into some troubles trying to keep
I'm trying to design a database for a small project I'm working on. Eventually,
I'm working on a small project in VB6, and am trying to fiddle with
I'm trying to learn GNUMake for a small project I'm working on. So far,
I'm working on a small project in C where I have to parse a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.