OK, probably the easiest thing to do would be to add some kind of state
functionality to the loop and use different logic/regex stuff based on
where in the process you are ... first test each line for '/^SHIP TO/',
'/^BILL TO/' or /^ORDER NO./ ... that could set your 'state' for the
script, then you can process each line properly (and it would get around
the ':' in an order line problem as you wouldn't execute on that basis
... in my head anyway that would make the main loop into a case
construct:

switch($stateofscript) {
        case SHIP:
                $shippinginfo[$matches[1]] = $matches[2];
                break;
        case BILL:
                $billinginfo[$matches[1]] = $matches[2];
                break;
        case ORDER:
                // split your order lines
                break;
        default;
                // must not have hit the SHIPPING INFO yet so do nothing
        }

The other thing you'll need to fix is that you have the generic
'address' tag for 3 different lines in both shipping and billing ... so
the logic will need to include a if(isset($shippinginfo[$matches[1]]))
thing to prepend or postfix an integer or something onto the index to
keep the lines straight.

I'd say you're getting there though.

Hank
                

On Sun, Nov 25, 2001 at 02:06:52PM -0700, Ashley M. Kirchner wrote:
> 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:[EMAIL PROTECTED]>   .   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.
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 

-- 
Hank Marquardt <[EMAIL PROTECTED]>
http://web.yerpso.net
GPG Id: 2BB5E60C
Fingerprint: D807 61BC FD18 370A AC1D  3EDF 2BF9 8A2D 2BB5 E60C
*** Web Development: PHP, MySQL/PgSQL - Network Admin: Debian/FreeBSD
*** PHP Instructor - Intnl. Webmasters Assn./HTML Writers Guild 
*** Beginning PHP -- Starts January 7, 2002 
*** See http://www.hwg.org/services/classes

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to