need help with regex


#1

Im trying to build my array but for some reason I can’t seem to get the Totals line in my array, I can get all the players + there numbers but can’t seem to add the Totals line to the array without getting in one of the ------- lines into the array as well. Here is my code and what it does so far.

First this is my 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 blur             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

Heres my code.

$strFilename = ("./ctf.txt");
$result = array();
	
	$strLog = file_get_contents($strFilename);
	$strLog = str_replace( array("n","rn"), "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];
  } 
 } 
} 

and here is my Array, notice how it doesn’t include the Totals line

Array =

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)
    }
  }
}

I think the problem is somewhere in my “preg_match_all( ‘/-{40,}r(.?)r-{40,}r(.?)/’, $strLog, $arrMatches );” line but im not entirely sure. Please help.


#2

can anyone help me out?


#3

This is defenitely no answer to your problem, but i may suggest; use mysql?

sorry man. :cry:


#4

Um, well I don’t think there’s really a problem with your regex, try seeing what’s in $arrMatches[2] and then make any necessary changes…