Variable matching...
| From: | Ashley M. Kirchner | Date: | Sat, 24 Nov 2001 10:28:05 +0000 |
| Subject: | Variable matching... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-75606@lists.php.net to get a copy of this message | ||
Can anyone help me with translating the following (which was
written in something else):
[NOTE: I've simplified the code for this purpose]
pairs = {{"First Name", "first_name"},{"Address",
"address"}};
while (data) {
line = split($data, " ");
for pair in (pairs) {
if (match(line[1], pair[1])) {
pair[2] = line[2];
}
}
}
The idea here is that 'pairs' contains a list of items that the
program uses, by matching the first item with 'data', and if it matches,
it sets the second item with whatever 'data' is passing. With the above
code, if 'data' was something like "First Name: John" (yes, with
the spaces before the name), the result will basically set first_name to
"John". And that variable 'first_name' can be used elsewhere in the
code. When the 'data' contains 'Address' in it, it'll set the variable
'address' to whatever the second value is in data.
The code itself contains a rather large set in 'pairs' that it goes
through while there's 'data' for it to parse. However, as you can see,
the code is also rather poorly written in that it cycles through the
entire list in 'pairs' for every single line of 'data' there is. (this
is why I'm trying to rewrite this whole beast into PHP and hopefully get
something better).
The data that comes flowing in looks like this:
First Name: John
Last Name: Doe
Address: 12345 Fairy Lane
Address:
City: White Clouds
State/Province: Cloud 9
Country: Heaven
etc.
etc. (there is more information that I need to capture after this)
--
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.