This is the code i ended up with at the end.
Thanks for the help.
[PHP]<?php
//killmail lines
$lines = split("\n", $email_body);
//get the timestamp
$timestamp = $lines[0];
/*Outline the plan....lets create three arrays:
Victim array:
* $victim[Victim]
* $victim[Alliance] (this will be null/blank if it doesn't exist)
* $victim[Corporation]
* $victim[Destroyed Type]
* $victim[Solar System]
* $victim[Security Level]
For each element (n) in the $involved array above you are dealing with an attacker
* $involved[n][Name]
* $involved[n][Security Status]
* $involved[n][Alliance] (this will be null/blank if it doesn't exist)
* $involved[n][Corporation]
* $involved[n][Ship Type]
* $involved[n][Weapon Type]
* $involved[n][Final Blow] (this is a boolean true/false)
The destoyed items array will have 3 fields for each element (n)
* $destroyed[n][Type]
* $destroyed[n][Location]
* $destroyed[n][Quantity]
*/
//lets find the location of the involved parties and destroyed items lines
for ($i = 0;$i < count($lines);$i++){
if(trim($lines[$i]) == "Involved parties:") {
$inv_loc = $i;
}else if(trim($lines[$i]) == "Destroyed items:") {
$dest_loc = $i;
}
}
//get victim info, start at line 2 go up to where we found the involved parties
for($i = 2;$i < $inv_loc;$i++){
if ( (trim($lines[$i]) != "")) {//working on a good line
unset($pair);
$pair = explode(": ", $lines[$i]);
$victim[$pair[0]] = $pair[1];
}
}
//lets assemble our killers by looking between the involved parties line and the destroyed items line
$inv_loc++; //add one so we start after the title line
for($i = $inv_loc;$i < $dest_loc;$i++){
$line = trim($lines[$i]);
if( ($line != "") && ($line != "**** Truncated - mail is too large ****") ){//working on a good line
unset($pair);
$pair = explode(": ", $line);
//clear array if on new killer
if($pair[0] == "Name") {
unset($killer);
if(substr_count($pair[1], "(laid the final blow)")) {
//found final killer get rid of final blow text
$pair[1] = substr($pair[1], 0, strlen($pair[1]) - 22);
$killer['Final Blow'] = 1;
}else {//not final killer
$killer['Final Blow'] = 0;
}
}
//add data onto killer array
$killer[$pair[0]] = $pair[1];
if($pair[0] == "Weapon Type") {
//finished, place the killer array onto the $involved stack
$involved[] = $killer;
}
}
}
//lets assemble the items that were destroyed
$dest_loc++;
for($i = $dest_loc; $i < count($lines); $i++){
$line = trim($lines[$i]);
if( ($line != "") && ($line != "**** Truncated - mail is too large ****") ){//working on a good line
unset($pair);
$pair = explode(": ", $line);
if($pair[0] != "Quantity") {//we only want the Type lines
unset($item);
//pull off the item name
$item_name = substr($pair[1], 0, strpos($pair[1], "("));
//pull off the location of the item; first pull from the last occurance of a ( then trim off the parenthesis
$item_loc = ltrim(rtrim(strrchr($pair[1], "("), ")"), "(");
$item['Type'] = $item_name;
$item['Location'] = $item_loc;
//check if this item has a quantity in the next line
$k = $i + 1;
if (substr_count($lines[$k], "Quantity: ")) {
$line = trim($lines[$k]);
unset($pair);
$pair = explode(": ", $line);
$item['Quantity'] = $pair[1];
}
//add this item to the stack
$destroyed[] = $item;
}
}
}
//now we're done lets echo out our data to see if we got it all right
echo "Victim: " . $victim['Victim'] . "
";
echo "Alliance: " . $victim['Alliance'] . "
";
echo "Corporation: " . $victim['Corporation'] . "
";
echo "Ship Lost: " . $victim['Destroyed Type'] . "
";
echo "Location: " . $victim['Solar System'] . "
";
echo "Security Level: " . $victim['Security Level'] . "
";
echo "
";
echo "There were " . count($involved) . " known involved parties.
";
echo "
";
foreach ($involved as $killer) {
if ($killer['Final Blow']) {
echo "The final blow was laid by:
";
echo "";
echo "Name: " . $killer['Name'] . "
";
echo "Security Status: " . $killer['Security Status'] . "
";
echo "Alliance: " . $killer['Alliance'] . "
";
echo "Corporation: " . $killer['Corporation'] . "
";
echo "Ship Type: " . $killer['Ship Type'] . "
";
echo "Weapon Type: " . $killer['Weapon Type'] . "
";
echo "";
echo "
";
}
}
echo "Other partied involved were:
";
echo "";
foreach ($involved as $killer) {
if(!$killer['Final Blow']) {
echo "Name: " . $killer['Name'] . "
";
echo "Security Status: " . $killer['Security Status'] . "
";
echo "Alliance: " . $killer['Alliance'] . "
";
echo "Corporation: " . $killer['Corporation'] . "
";
echo "Ship Type: " . $killer['Ship Type'] . "
";
echo "Weapon Type: " . $killer['Weapon Type'] . "
";
echo "
";
}
}
echo "";
echo "
";
echo "Items destroyed in this ship loss:
";
echo "";
echo "High Slot Items:
";
foreach ($destroyed as $item) {
if ($item['Location'] == "Fitted - High slot") {
//only high slot items have ammo
if($item['Quantity'] == ""){
echo $item['Type'] . "
";
}else {
echo $item['Quantity'] . " x " . $item['Type'] . "
";
}
}
}
echo "
";
echo "Medium Slot Items:
";
foreach ($destroyed as $item) {
if ($item['Location'] == "Fitted - Medium slot") {
echo $item['Type'] . "
";
}
}
echo "
";
echo "Low Slot Items:
";
foreach ($destroyed as $item) {
if ($item['Location'] == "Fitted - Low slot") {
echo $item['Type'] . "
";
}
}
echo "
";
echo "Cargo Items:
";
foreach ($destroyed as $item) {
if ($item['Location'] == "Cargo") {
//looks like Eve counts weird here but meh, lets show quantity all the time setting nulls to 1
if ($item['Quantity'] == "") $item['Quantity'] = 1;
echo $item['Quantity'] . " x " . $item['Type'] . "
";
}
}
echo "";
?>[/PHP]