Jump to content

Help extracting information from email


alohatofu

Recommended Posts

Hello,

 

I'm wondering if it is possible to extract some information from an email and assign them $variables to it. I'm new at regex. I took a unix class but that was 10 years ago I was wondering if some regex masters out there give me a hand.

 

first of all here is the text:

Event Notification

--------------------------------

Planned Event Report

Final Notification

NEED: the first word from the 3rd line. It should be Planned. Assign it value $priority

 

Date/Time of Event:

04/17/07 12:00 AM PDT

Services Impacted:

NEED: extract the date from it and assign it $startdate

 

 

Number of Customers Impacted By Service:

ABC - DSLAMs: 466

Estimated Restoral:

NEED: extract the number after DSLAMs: and assign it $customers

 

 

04/13/07  3:06 PM PDT

This is the paragraph that I would like

another line here for example.

 

Notice ID: 0068634

NEED: extract the paragraph after the date. assign it $descriptions

 

 

Notice ID: 0068634

Master Event ID: 0028898

NEED: here's a tricky one. on the Master event ID line, I want only the last 5 digits and assign them $masterid

 

this is a line with 2007041300769953 and numbers and letters

NEED: find the 16 digits number and assign it $digitnumbers

 

 

The rest I can figure out by using the examples you provide me.

 

thank you very much in advance!

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/47375-help-extracting-information-from-email/
Share on other sites

Event Notification

--------------------------------

Planned Event Report

Final Notification

 

NEED: the first word from the 3rd line. It should be Planned. Assign it value $priority

// First word, third line:
$pattern = '/.*?\n.*?\n(\w+)/';
preg_match($pattern,$your_string,$match);
$priority = $match[1];

I'll just give you the pattern from here; the rest is the same.

Date/Time of Event:

   04/17/07 12:00 AM PDT

Services Impacted:

 

NEED: extract the date from it and assign it $startdate

|(\d\d/\d\d/\d\d\s+\d+:\d\d\s+(?:A|P)M\s+\w{3})|

Number of Customers Impacted By Service:

   ABC - DSLAMs: 466

Estimated Restoral:

 

NEED: extract the number after DSLAMs: and assign it $customers

// Is DSLAMs always going to be DSLAMs?  If so:
/DSLAMs:\s*(\d+)/

 

04/13/07  3:06 PM PDT

This is the paragraph that I would like

another line here for example.

 

Notice ID: 0068634

 

NEED: extract the paragraph after the date. assign it $descriptions

|\d\d/\d\d/\d\d\s+\d+:\d\d\s+(?:A|P)M\s+\w{3}\n(.*?)\n\s*\n|

Notice ID: 0068634

Master Event ID: 0028898

 

NEED: here's a tricky one. on the Master event ID line, I want only the last 5 digits and assign them $masterid

/Master Event ID:.*?(\d{5})$/

this is a line with 2007041300769953 and numbers and letters

 

NEED: find the 16 digits number and assign it $digitnumbers

// That's not hard....
/\w{16}/
// ...or...
/[A-Z0-9]{16}/i

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.