Re: Creating $key, $value pairs
| From: | Hank Marquardt | Date: | Sun, 25 Nov 2001 19:30:05 +0000 |
| Subject: | Re: Creating $key, $value pairs | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-75670@lists.php.net to get a copy of this message | ||
> Actually, some of those will end up being "blank", for example the 'BILL
> TO:' line is always blank, I may not have all 3 lines of 'Address:' filled, etc.,
> etc. And there may be more lines that might end up blank when someone places an order. And as you
> pointed out, some lines might have :'s elsewhere in it. The 'Today's Date:'
> line is one of those. And nothing is going to stop anyone from doing something like 'From:
> Santa, To: Rudolph' in the 'Gift Message:' field. So I suppose I need to look out
> for those, I just don't know who just yet. (and considering how much I *suck* at regexp
> matching, that's going to be rather tricky for me)
>
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:)
> Either way, thank you very much for your code. It is a great start for what I need done.
> Thanks!
>
You're welcome:) ... the regexs aren't that bad here, just picky; 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.
Good luck
Hank
--
Hank Marquardt <hank@yerpso.net>
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