newphpuser Posted January 7, 2013 Share Posted January 7, 2013 (edited) Hello Everyone, I have different entries in a log file in the form: ================================================[Jan 27 2012 12:10:35] - ID2PDF v.2.6 (ID2PDF.jsx)General options: [default] (ID2PDF_options.xml)================================================Loaded options from XML file: 'path/to/file/some_file.xmlextendedPrintPDF startedextendedPrintPDF: Error: Unsaved documents have no full name.; line: 332================================================[Jan 27 2012 12:12:57] - ID2PDF v.2.6 (ID2PDF.jsx)General options: [default] (ID2PDF_options.xml)================================================Error opening document: path/to/file/some_file1: Error: Either the file does not exist, you do not have permission, or the file may be in use byanother application; line: 190Error opening document: path/to/file/some_file2: Error: Either the file does not exist, you do not have permission, or the file may be in use byanother application; line: 190 I want to grab the time in the first line of the record (I can manage that with a RegEx, alright!) and then compare it with the time of the next entry (in this case, with Jan 27 12:12:57). And if the second time is greater than the first, I want to read the rest of the text file and do a bunch of other things.Is it possible to do this?NOTE: The entries may have records of any number of lines, but each entry is separated by the === delimiter. Edited January 7, 2013 by newphpuser Link to comment Share on other sites More sharing options...
justsomeguy Posted January 7, 2013 Share Posted January 7, 2013 Separate the entries and get the timestamps with a regular expression if they are there. You can use strtotime to convert the text to a timestamp, and then do your comparison from there. http://www.php.net/manual/en/function.strtotime.php Link to comment Share on other sites More sharing options...
newphpuser Posted January 7, 2013 Author Share Posted January 7, 2013 Thanks! :)And what about the second part? If the second time is greater, continue reading the whole file and performing some actions. If not, just terminate. How should I go about that? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 7, 2013 Share Posted January 7, 2013 "Terminate" may mean using exit, return, or break, depending on the rest of your code. Link to comment Share on other sites More sharing options...
newphpuser Posted January 7, 2013 Author Share Posted January 7, 2013 I mean, just exiting the program for then. But, how can I ask it to continue reading the remaining text file, but NOT read the part before the previous date & time? Like, in this case, if it finds Jan 27 2012 12:12:57, I want to force it to read the text STARTING from this record and forget the previous records, so as to avoid duplication-- which may occur if it reads older records. Link to comment Share on other sites More sharing options...
jeffman Posted January 7, 2013 Share Posted January 7, 2013 I would personally find a way to explode the file into an array of unique records. Walk through each element of the array. Check the date of each one. And so on. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 7, 2013 Share Posted January 7, 2013 You can also use usort to sort your array of records by a custom criterion, in this case your timestamps. Link to comment Share on other sites More sharing options...
jeffman Posted January 8, 2013 Share Posted January 8, 2013 Totally. Build the regex right into that. Especially if you already have one that's working. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now