Compare Today's date with date from text file

Posted on 2006-05-20
Last Modified: 2012-05-05
Hi, 'sperts.

I am using the following code (compiled from many ee searches) to read, isolate, and print only certain rows from a text file. The rows must contain a certain IP address and another number, each of which are contained in the resulting array as $data[0] and $data[3]. The script below works great:

$row = 1;
$handle = fopen("mytext.txt", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
   $num = count($data);
   echo "<p> $num fields in line $row: <br /></p>\n";
   for ($c=0; $c < $num; $c++) {
               if (($data[0] == "//ip_address_here//") && ($data[3] == "192875231")) {
                  echo $data[$c] . "<br />\n";

I want to add another arguement to the line from above:

if (($data[0] == "//ip_address_here//") && ($data[3] == "192875231")) && "The current date is three months past the date in the text file"

Here is the issue:

The date located in the text file (returned in the array as $data[2]) has this format:

Fri May 19 17:07:59 EDT 2006

I thought I could use 'strtotime' to convert this to a timestamp, and compare that with today's timestamp, but strtotime doesn't like the format from the text file (see above, it returns a result of '-1'). Is there another function I could use to convert the date from the text file to a usable format, or is there a way to compare the date 'as it is' to today's date?

Question by:admash
    LVL 49

    Accepted Solution

    strtotime accepts 'Fri May 19 2006', so you can try and do a preg_replace on $data[2];

    $data[2] = preg_replace('/\d\d:\d\d:\d\d[^\d]+/', '', $data[2]);


    Author Comment

    That got it! Thaks a million.

    (or at least, 500)



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now