This is a bit crude but should work:
<?php
$data = <<<EOT
SHIP TO:
Business Name:
Contact Name: Ashley Kirchner
Day Number: 303 442-6410
Evening Number:
Fax Number:
Address: 3550 Arapahoe Ave., Ste. #6
Address:
Address:
City: Boulder
State/Province: CO
Zip/Postal Code: 80303
Country: USA
BILL TO:
Business Name:
Contact Name: Ashley M. Kirchner
Day Number: 303 4426410
Evening Number:
Fax Number: 303 442-9010
Address: 3550 Arapahoe Avenue
Address: Suite #6
Address:
City: Boulder
State/Province: CO
Zip/Postal Code: 80303
Country: USA
EOT;
$ship_to = array();
$bill_to = array();
$state = 0; // 0 = ship_to, 1 = bill_to
function create_data ($s)
{
global $ship_to;
global $bill_to;
global $state;
$s[1] = trim ($s[1]);
$s[2] = trim ($s[2]);
if (!strcmp ($s[1], 'SHIP TO'))
$state = 0;
elseif (!strcmp ($s[1], 'BILL TO'))
$state = 1;
else
{
if ($state)
$bill_to[$s[1]] = $s[2];
else
$ship_to[$s[1]] = $s[2];
}
return $s[0];
}
preg_replace_callback ("/(.*)\:[ ]*(.*)?[\n]?/", "create_data", $data);
print_r ($ship_to);
print_r ($bill_to);
?>
Note that I made a bunch of assumptions here--that the data is always
properly formatted, that there is only one record in the $data, and that
you will later manipulate the key names so that they will actually work
as database columns. Still, this way you can manipulate each value
directly in the function, which is something that I always find very
practical, so you can add whatever additional checks need to be
performed.
Hope this helps!
Cheers,
Marco
--
------------
php|architect - The magazine for PHP Professionals
The monthly worldwide magazine dedicated to PHP programmers
Come visit us at http://www.phparch.com!
--- Begin Message ---
I have the following bit of information coming in that I need to
generate key pairs of so I can drop it all into a database. I'm
creating tables for each section (SHIP_TO and BILL_TO) with matching
Unique_IDs. What's the best way to go about this (creating the pairs,
stripping off excess spaces from some fields that have them after the
last character, etc., etc.)
---------- data ----------
SHIP TO:
Business Name:
Contact Name: Ashley Kirchner
Day Number: 303 442-6410
Evening Number:
Fax Number:
Address: 3550 Arapahoe Ave., Ste. #6
Address:
Address:
City: Boulder
State/Province: CO
Zip/Postal Code: 80303
Country: USA
BILL TO:
Business Name:
Contact Name: Ashley M. Kirchner
Day Number: 303 4426410
Evening Number:
Fax Number: 303 442-9010
Address: 3550 Arapahoe Avenue
Address: Suite #6
Address:
City: Boulder
State/Province: CO
Zip/Postal Code: 80303
Country: USA
----------
--
W | I haven't lost my mind; it's backed up on tape somewhere.
+--------------------------------------------------------------------
Ashley M. Kirchner <mailto:[EMAIL PROTECTED]> . 303.442.6410 x130
IT Director / SysAdmin / WebSmith . 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, visit: http://www.php.net/unsub.php
--- End Message ---
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php