Re: Creating $key, $value pairs
| From: | Ashley M. Kirchner | Date: | Sun, 25 Nov 2001 21:06:52 +0000 |
| Subject: | Re: Creating $key, $value pairs | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-75672@lists.php.net to get a copy of this message | ||
Hank Marquardt wrote:
> Actually you're OK here (I think ...) if a few of them end up blank,
> that's OK, just ignore them, you'll know the ones you want based on the
> real email you receive ... as for the folks putting To: someone, From:
> someone ... I wrote the regex to accomodate that ... it takes anything
> up to the first ':' and claims that as the variable name, then discards
> the ':' after and finally grabs the rest of the line (.*) as the
> remainder ... that can include ':' without problem ... in fact if you
> look at your example, it handles the first 'timestamp' field just fine:)
Yeap, I noticed that as soon as I ran the first (full) email through it. And of course,
there're some problems. The incoming email has two "sections" in it which will
contain the same variables. What I posted only contained a 'BILL TO:' section. The full
email also contains a 'SHIP TO:' section. But because the script creates variables based
on the fields in the email, it overwrites the first section:
SHIP TO:
Business Name:
Contact Name: PhotoCraft
Day Number: 303.442.6410
Evening Number:
Fax Number:
Address: 3550 Arapahoe Ave
Address: Suite 6
Address:
City: Boulder
State/Province: CO
Zip/Postal Code: 80303
Country: USA
BILL TO:
Business Name:
Contact Name: Ashley M. Kirchner
Day Number: 800 555-1212
Evening Number: 303 555-1212
Fax Number:
Address: 3550 Arapahoe Ave #6
Address:
Address:
City: Boulder
State/Province: CO
Zip/Postal Code: 80303
Country: USA
This is part of why I asked whether it was possible to use my own variable naming, so I could
end up with one of:
$ShipToContact $BillToContact
$ShipToDayPhone $BillToDayPhone
$ShipToEvePhone $BillToEvePhone
or:
$ShipTo['contact'] $BillTo['contact']
$ShipTo['DayPhone'] $BillTo['dayphone']
$ShipTo['EvePhone'] $BillTo['evephone']
And then there's still the order items themselves. Right now, the script is cutting the
lines because of the : matching. So, a line like this (wrapping alert):
ORDER NO. QTY UNIT DESCRIPTION PRICE TOTAL
4x6 1 4"x6" Standard Print (full-frame from 35mm) Image:Uploaded Image 1 .75
$0.75
...will end up:
$key: 4x614x6StandardPrint(full-framefrom35mm)Image
$val: 'Uploaded Image 1 .75 $0.75'
ORDER HERE:
Item: 0
Itemnum -> 4x6
Quantity -> 1
Not quite what it should be. I think I'm going to limit where it should do the $key ->
$value matching, and figure something else out for the rest of the message.
> the
> whole thing would be a lot easier in the last one if they actually tab
> delimit the fields, then a simple split() call would handle it nicely
> but what you posted was spaces.
Yeah, the original incoming email is a mess really. No tab delimited anything, and some of the
fields have extraneous spaces after each value, some just have a row of spaces (if the value's
blank), some 80 characters long.
--
H | "Life is the art of drawing without an eraser." - John Gardner
+--------------------------------------------------------------------
Ashley M. Kirchner <mailto:ashley@pcraft.com> .
303.442.6410 x130
Director of Internet Operations / SysAdmin . 800.441.3873 x130
Photo Craft Laboratories, Inc. . 3550 Arapahoe Ave, #6
http://www.pcraft.com ..... . . . Boulder, CO 80303,
U.S.A.