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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:26:16+00:00 2026-05-12T11:26:16+00:00

Is there a way to take text like below (if it was already in

  • 0

Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range?

For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so?

date,test,time,avail
2009-09-01,JS,0.119,99.90
2009-09-02,JS,0.154,99.89
2009-09-03,SWF,0.177,99.90
2009-09-04,SWF,0.177,99.90
2009-09-05,SWF,0.177,99.90
2009-09-06,SWF,0.177,99.90
2009-09-07,SWF,0.177,99.90
2009-09-08,SWF,0.177,99.90
2009-09-09,SWF,0.177,99.90
2009-09-10,SWF,0.177,99.90

Thanks!

  • 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-05-12T11:26:16+00:00Added an answer on May 12, 2026 at 11:26 am

    (This solution is in PHP — but you can probably do that directly from the command-line, I suppose, with somekind of grep or anything)

    Considering your dates are in the YYYY-MM-DD format, and that they are at the beginning of each line, you just have to compare the lines alphabetically to compare the dates.

    One solution would be to :

    • load the string
    • explode it by lines
    • remove the first line
    • iterate over the lines, keeping only those that interest you

    For the first parts :

    $str = <<<STR
    date,test,time,avail
    2009-09-01,JS,0.119,99.90
    2009-09-02,JS,0.154,99.89
    2009-09-03,SWF,0.177,99.90
    2009-09-04,SWF,0.177,99.90
    2009-09-05,SWF,0.177,99.90
    2009-09-06,SWF,0.177,99.90
    2009-09-07,SWF,0.177,99.90
    2009-09-08,SWF,0.177,99.90
    2009-09-09,SWF,0.177,99.90
    2009-09-10,SWF,0.177,99.90
    STR;
    $lines = explode(PHP_EOL, $str);
    unset($lines[0]); // first line is useless
    

    And, to iterate over the lines, filtering in/out those you want / don’t want, you could use a foreach loop… Or use the array_filter function, which exists just for this 😉

    For instance, you could use something like this :

    $new_lines = array_filter($lines, 'my_filter');
    var_dump($new_lines);
    

    And your callback function would be :

    function my_filter($line) {
        $min = '2009-09-04';
        $max = '2009-09-09';
        if ($line >= $min && $line <= $max) {
            return true;
        } else {
            return false;
        }
    }
    

    And, the result :

    array
      4 => string '2009-09-04,SWF,0.177,99.90' (length=26)
      5 => string '2009-09-05,SWF,0.177,99.90' (length=26)
      6 => string '2009-09-06,SWF,0.177,99.90' (length=26)
      7 => string '2009-09-07,SWF,0.177,99.90' (length=26)
      8 => string '2009-09-08,SWF,0.177,99.90' (length=26)
    

    Hope this helps 😉

    If your dates where not in the YYYY-MM-DD format, or not at the beginning of each line, you’d have to explode the lines, and use strtotime (or do some custom parsing, depending on the format), and, then, compare timestamps.

    But, in your case… No need for all that 😉

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

Sidebar

Related Questions

Is there some way I can take text (retrieved from a form), and email
Is there a way to take a compiled SWF file and figure out how
Is there any convenient way to take an array/set of objects and create a
I would like to know if there is a way to take create a
I'd like to find a way to take a piece of user supplied text
Ok so I'm trying to take an input text file and justify it like
Is there a way to easily take 3 text files and turn it into
Hello is there a way to take the content of a php file while
I have a text file which contains several hundred lines e.g. test.bin:8948549854958 They are
The program below should take an array and compress it so that there are

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.