Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting "Date: ..." line from a text file

Status
Not open for further replies.

anticore

Technical User
Aug 26, 2001
32
HK
Hey,

I have a file stored in the following format:
From: SomeOne
Date: dd/mm/yyyy, time
Details: blah blah
From: SomeOneElse
Date: dd/mm/yyy, time
Details: more blah
...

What I am trying to do is extract the last Date: line from this file. There are no guarantees on the number of lines of the Details: part...

I am trying to use regular expression to match all the Date lines and add 'em to an array and get the last one. But can't quite get it.

Any help appreciated..

Anticore...
 
When you need the last date you dont have to use array's. If you use a string that is overwritten every time there is a new date, you will eventually end up with tha last date.
with fgets you can get a line from a file.
You want to use regular expressions, thats ok:
if (ereg(^Date:))
fgets ($fp, 4096)

Then you strip the Date:
$result_dateline = substr($dateline, 5);
and remove the whitespace:
trim($result_dateline);

Hope this helps mcvdmvs
-- "It never hurts to help" -- Eek the Cat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top