I am currently working on building a system for my client that could be classed as a type of ticket system. However, instead of users inputting tickets like a normal system, the tickets are received from a third party (always the same third party) in email format that will be piped in.
What I need to look at (which I’ve thought using various ways but cant seem to pick out the best) is taking the details from the email and putting them into individual variables.
An example of the email that will be recieved is:
Name: Harry Smith
Status: Married
Address: 14 Tyne Road,
Littlewood
Manchester
MC2 3DN
Telephone: 01551 221502
Obviously the full email is alot longer, however what I am looking at doing is putting out the details from the email so I can process them as required by the new system. In reality I am looking for something that can store the information in the style of:
Name: %name%
Status: %status%
Address: %address%
Telephone: %telephone%
I just haven’t quite worked out how to code a string search that will find Name: and store every after it up until Status: is reached.
Any help or pointers would be great.
Thanks 🙂
Read the data file in line by line. Explode each line with a “:”. If a count of that == 2 then you know you are on a new token, and in which case the key = index[0] and the value = index[1]. Now check the next line, if there is only one element after you run explode, simply add it to the previous key.