PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
gar
Forum Newbie
Posts: 3 Joined: Sun Jan 15, 2006 7:00 pm
Post
by gar » Sun Jan 15, 2006 7:10 pm
Hi everybody,
I am grabbing emails from a pop3 mailbox and the body is in this format:
Code: Select all
subject: blah blah
Name: Andrew
Company: whatever
MSISDN: 12323232321
Email: acsXcz@whatever.com
Camera: yes
UseSMS: yes
SMSsent: yes
UseMMS: yes
MMSsent: yes
Ringtone: yes
Operator: Vodafone
Favourite: Dance
Question: when is th event?
Interactive: Yes
Timestamp: 13/01/2006 13:30
ive never parsed strings before with php. how would i go about plucking out the MSISDN and the operator?
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Sun Jan 15, 2006 7:41 pm
Code: Select all
<?php
$lines = explode('\n', $email);
$data = array();
foreach ($lines as $line) {
list($key, $val) = explode(': ', $line);
$data[trim($key)] = trim($val);
}
?>
Where $email contains the contents of the mail as a string.
Last edited by
Jenk on Sun Jan 15, 2006 7:49 pm, edited 1 time in total.
gar
Forum Newbie
Posts: 3 Joined: Sun Jan 15, 2006 7:00 pm
Post
by gar » Sun Jan 15, 2006 7:48 pm
awesome! thank you
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Sun Jan 15, 2006 7:50 pm
I had a stray 0 in the line "$data = array();" I have updated
gar
Forum Newbie
Posts: 3 Joined: Sun Jan 15, 2006 7:00 pm
Post
by gar » Tue Jan 17, 2006 3:00 am
after messing with this for literally HOURS i realised you need double quotes around the \n
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Tue Jan 17, 2006 3:35 am
doh!
My bad, sorry.