?
Solved

Compare Today's date with date from text file

Posted on 2006-05-20
2
Medium Priority
?
319 Views
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:

<?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
0
Comment
Question by:admash
2 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 2000 total points
ID: 16725690
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
 

Author Comment

by:admash
ID: 16725725
That got it! Thaks a million.

(or at least, 500)

:-)

Aaron
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
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 …
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

850 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