Compare Today's date with date from text file

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:

<?php
$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";
   $row++;
   for ($c=0; $c < $num; $c++) {
               if (($data[0] == "//ip_address_here//") && ($data[3] == "192875231")) {
                  echo $data[$c] . "<br />\n";
                }
   }
}
fclose($handle);
?>

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?

Thanks!
Aaron
admashAsked:
Who is Participating?
 
RoonaanCommented:
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]);

-r-
0
 
admashAuthor Commented:
That got it! Thaks a million.

(or at least, 500)

:-)

Aaron
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.