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 8436525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:12:03+00:00 2026-06-10T07:12:03+00:00

Ok, Ive had a question on this before. I found out how to delete

  • 0

Ok, Ive had a question on this before.

I found out how to delete lines in a txt file using php based on unix time

this is my current code.

<?php
$output = array();
$lines = file('file.txt');
$now = time();

foreach ($lines as $line) {
  list($content, $time) = explode("|", $line);
  if ($time > $now) {
 $output[] = $line;
 }
 }
 $outstring = implode($output);
file_put_contents("file.txt", $outstring);
print time();
?>

What that code does is every entry in the file will have a time next to it in Unix

So

Its set up like this

Content | Unix Time
Content | Unix Time

What I Want to do is Have a PHRASE or WORD In replace of the unix time, that indicates that line needs to stay there.

Is there a snippet or would this be hard?

Any Help would be appreciated.

  • 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-10T07:12:04+00:00Added an answer on June 10, 2026 at 7:12 am

    Adding

    $keepStr = "KEEP";
    

    at the top and replacing the foreach loop with:

    foreach ($lines as $line) {
        list($content, $value) = explode("|", $line);
        if ($value == $keepStr || $value > time() ) {
           $output[] = $line;
        }
    }
    

    would convert

    Content1 | KEEP
    Content2 | Somevalue
    Content3 | Someothervalue
    Content4 | KEEP
    

    To

    Content1 | KEEP
    Content4 | KEEP
    

    You can define the string to keep as whatever you like by changing the value given to $keepStr

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

Sidebar

Related Questions

Ive had a similar question as this one before, and when that solved this
I've seen this question asked around before, and found an answer for how to
I've had a look at Stack Overflow question Initialization of a microSD card using
Has anyone had experience using SSL with net.tcp binding in WCF? Ive read its
I am trying to delete the session cookie and havent had any success. Ive
I've kind of asked this question before - What does JVM flag CMSClassUnloadingEnabled actually
In this question I asked about NHibernate session lifetime. I'm using a desktop application,
To preface, I've seen the command to answer this question before, but now I
This is a question about credit card processing. We are using AVS and have
Variations of this question have been asked before, but it seems like the issue

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.