Who loves you, croft? That's right, Troy does! Here is complete, working, tested code to parse your email body into the various data pieces. Just create the two files below, and place on a PHP enabled web server. Then surf to the eve_submit.htm web page.
NOTE: Text parsing is a tricky business. One small change in the text format may break your parsing script.
Create this HTML page:
eve_submit.htm
<html>
<head>
<title></title>
</head>
<body>
<form method="POST" action="eve_parse.php">
<textarea name="email_body" cols="80" rows="20"></textarea>
<br /><input type="submit" />
</form>
</body>
</html>
Create this PHP script:
eve_parse.php
[php]
<?php
/*
Put the text that was passed in via HTTP into a variable.
*/
$email_body = $_REQUEST['email_body'];
/*
Create an array to hold the key -> value pairs.
*/
$data = array();
/* Create an array where each line of text is in an array element. */
$lines = split("\n", $email_body);
/*
Since the timestamp is the very first line of the text, go ahead and put this
into a variable.
*/
$data['timestamp'] = trim($lines[0]);
/*
Now iterate through the lines breaking each into it's key->value set.
Do this until we reach the "Destroyed items" section.
*/
for ($line_idx=1; $line_idx<count($lines); $line_idx++) {
$line = $lines[$line_idx];
$pair = split(":", trim($line));
$pair[0] = trim($pair[0]);
$pair[1] = trim($pair[1]);
if ($pair[0] == "Destroyed items") { break; }
if ((strlen($pair[0]) > 0) && (strlen($pair[1]) > 0)) {
$data[$pair[0]] = $pair[1];
}
}
/*
Now iterate through the destroyed items.
*/
$data['destroyed items'] = array();
for ($line_idx=$line_idx+1; $line_idx<count($lines); $line_idx++) {
$line = $lines[$line_idx];
$pair = split(":", trim($line));
$pair[0] = trim($pair[0]);
$pair[1] = trim($pair[1]);
if ((strlen($pair[0]) > 0) && (strlen($pair[1]) > 0)) {
if ($pair[0] == "Type") {
$item = array();
$item[] = $pair[1];
$line_idx++;
$line = $lines[$line_idx];
$pair = split(":", trim($line));
$pair[0] = trim($pair[0]);
$pair[1] = trim($pair[1]);
if ((strlen($pair[0]) > 0) && (strlen($pair[1]) > 0)) {
$item[] = $pair[1];
} else {
$item[] = 1;
}
$data['destroyed items'][] = $item;
}
}
}
/*
Dump the data array contents to the browser for testing purposes.
*/
echo "<pre>";
print_r($data);
echo "</pre>";
/*
You can directly access any item within the data array like so:
echo $data['Victim'];
To grab the values for the fourth destroyed item:
echo "Item #4 Name: ".$data['destroyed_items'][3][0];
echo "Item #4 Qty: ".$data['destroyed_items'][3][1];
(Remember, PHP arrays are zero-indexed, so counting starts at zero.)
Now you can insert whatever you want into your database.
*/
?>
[/php]
The program, when passed the email example you posted, outputs:
Array
(
[timestamp] => 2005.06.04 03:35:00
[Victim] => name of killed person here
[Alliance] => Firmus Ixion
[Corporation] => Corp name here
[Destroyed Type] => Kestrel
[Solar System] => H74-B0
[System Security Level] => 0.0
[Name] => name of killer here (laid the final blow)
[Security Status] => 5.0
[Ship Type] => Megathron
[Weapon Type] => 425mm Railgun II
[destroyed items] => Array
(
[0] => Array
(
[0] => Standard Missile Launcher I (Fitted - High slot)
[1] => 1
)
[1] => Array
(
[0] => Standard Missile Launcher I (Fitted - High slot)
[1] => 1
)
[2] => Array
(
[0] => Warp Disruptor I (Fitted - Medium slot)
[1] => 1
)
[3] => Array
(
[0] => Standard Missile Launcher I (Fitted - High slot)
[1] => 1
)
[4] => Array
(
[0] => Sabretooth Light Missile I (Cargo)
[1] => 100
)
[5] => Array
(
[0] => Bloodclaw Light Missile I (Cargo)
[1] => 50
)
[6] => Array
(
[0] => Bloodclaw Light Missile I (Cargo)
[1] => 50
)
[7] => Array
(
[0] => Sensor Booster I (Fitted - Medium slot)
[1] => 1
)
[8] => Array
(
[0] => Barton Reactor Capacitor Recharger I (Cargo)
[1] => 1
)
[9] => Array
(
[0] => Medium Automated Structural Restoration (Cargo)
[1] => 1
)
[10] => Array
(
[0] => Flameburst Light Missile I (Fitted - High slot)
[1] => 36
)
[11] => Array
(
[0] => Bloodclaw Light Missile I (Fitted - High slot)
[1] => 36
)
)
)