My problem seems to be rather tuff it seems, I have a text file that contains some players and numbers seperated by ----. Anyhow im trying to populate my array and so far im getting all the players and there data in my array but im having no luck with getting the Totals lines to display without getting the ----- lines mixed in.
Here is my file, "ctf.txt"
Map: CPMCTF1
Time Remaining: MATCH COMPLETE
TEAM Player Kll Dth FC FTime FA TD FR Score
-------------------------------------------------------
RED Stripe 6 19 0 0:28.8 0 1 3 14
RED Sarge 6 20 0 0:32.4 0 3 1 13
RED Daemia 5 17 0 0:42.6 0 2 0 9
RED Doom 5 13 0 0:00.0 0 2 0 8
RED Grunt 3 15 0 0:22.5 0 0 0 4
-------------------------------------------------------
RED Totals 25 84 0 2:06.3 0 8 4 0
TEAM Player Kll Dth FC FTime FA TD FR Score
-------------------------------------------------------
BLUE craky 45 5 5 3:22.2 1 15 7 112
BLUE Major 15 4 0 0:00.0 0 3 1 25
BLUE Keel 9 4 0 0:00.0 1 2 2 21
BLUE Bitterman 7 7 0 0:26.2 0 3 2 17
BLUE Biker 8 5 0 0:57.2 0 3 1 15
-------------------------------------------------------
BLUE Totals 84 25 5 4:45.6 2 26 13 5
FC: Flag Captures TD: Team Defense
FA: Flag Assists FR: Flag Recovery
Current time: 12:17:07 (25 Jun 2004)
Dumped console text to stats/2004.06.25/121707.txt.
And this is my code so far...
$strFilename = ("./ctf.txt");
$result = array();
$strLog = file_get_contents($strFilename);
$strLog = str_replace( array("\n","\r\n"), "\r", $strLog );
preg_match_all( '/-{40,}\r(.*?)\r-{40,}\r(.*?)/', $strLog, $arrMatches );
foreach( $arrMatches[1] as $strPlayers ) {
$arrPlayers = explode("\r", $strPlayers);
foreach( $arrPlayers as $strData ) {
if ($strData) {
$arrData = preg_split('/[\s]+/', trim($strData));
$result[$arrData[0]][$arrData[1]]['kll'] += $arrData[2];
$result[$arrData[0]][$arrData[1]]['dth'] += $arrData[3];
$result[$arrData[0]][$arrData[1]]['fc'] += $arrData[4];
$result[$arrData[0]][$arrData[1]]['ftime'] += $arrData[5];
$result[$arrData[0]][$arrData[1]]['fa'] += $arrData[6];
$result[$arrData[0]][$arrData[1]]['td'] += $arrData[7];
$result[$arrData[0]][$arrData[1]]['fr'] += $arrData[8];
$result[$arrData[0]][$arrData[1]]['score'] += $arrData[9];
}
}
}
Also this is a sample of what my array looks like with this code
array(2) {
["RED"]=>
array(5) {
["Stripe"]=>
array(8) {
["kll"]=>
int(6)
["dth"]=>
int(19)
["fc"]=>
int(0)
["ftime"]=>
int(0)
["fa"]=>
int(0)
["td"]=>
int(1)
["fr"]=>
int(3)
["score"]=>
int(14)
}
["Sarge"]=>
array(8) {
["kll"]=>
int(6)
["dth"]=>
int(20)
["fc"]=>
int(0)
["ftime"]=>
int(0)
["fa"]=>
int(0)
["td"]=>
int(3)
["fr"]=>
int(1)
["score"]=>
int(13)
}
["Daemia"]=>
array(8) {
["kll"]=>
int(5)
["dth"]=>
int(17)
["fc"]=>
int(0)
["ftime"]=>
int(0)
["fa"]=>
int(0)
["td"]=>
int(2)
["fr"]=>
int(0)
["score"]=>
int(9)
}
["Doom"]=>
array(8) {
["kll"]=>
int(5)
["dth"]=>
int(13)
["fc"]=>
int(0)
["ftime"]=>
int(0)
["fa"]=>
int(0)
["td"]=>
int(2)
["fr"]=>
int(0)
["score"]=>
int(8)
}
["Grunt"]=>
array(8) {
["kll"]=>
int(3)
["dth"]=>
int(15)
["fc"]=>
int(0)
["ftime"]=>
int(0)
["fa"]=>
int(0)
["td"]=>
int(0)
["fr"]=>
int(0)
["score"]=>
int(4)
}
}
["BLUE"]=>
array(5) {
["blur"]=>
array(8) {
["kll"]=>
int(45)
["dth"]=>
int(5)
["fc"]=>
int(5)
["ftime"]=>
int(3)
["fa"]=>
int(1)
["td"]=>
int(15)
["fr"]=>
int(7)
["score"]=>
int(112)
}
["Major"]=>
array(8) {
["kll"]=>
int(15)
["dth"]=>
int(4)
["fc"]=>
int(0)
["ftime"]=>
int(0)
["fa"]=>
int(0)
["td"]=>
int(3)
["fr"]=>
int(1)
["score"]=>
int(25)
}
["Keel"]=>
array(8) {
["kll"]=>
int(9)
["dth"]=>
int(4)
["fc"]=>
int(0)
["ftime"]=>
int(0)
["fa"]=>
int(1)
["td"]=>
int(2)
["fr"]=>
int(2)
["score"]=>
int(21)
}
["Bitterman"]=>
array(8) {
["kll"]=>
int(7)
["dth"]=>
int(7)
["fc"]=>
int(0)
["ftime"]=>
int(0)
["fa"]=>
int(0)
["td"]=>
int(3)
["fr"]=>
int(2)
["score"]=>
int(17)
}
["Biker"]=>
array(8) {
["kll"]=>
int(8)
["dth"]=>
int(5)
["fc"]=>
int(0)
["ftime"]=>
int(0)
["fa"]=>
int(0)
["td"]=>
int(3)
["fr"]=>
int(1)
["score"]=>
int(15)
}
}
}
As you can see no Totals Line, for some reason its not being added to the array, and help would be great thanks.