[Help] Parse some words from a txt file and print them

hello i have a txt file wich are taken from a game log.
i tryed wth prematch but can’t seccessfuly.
i got on the txt file wich i want parse

[php]
27:16 D;011000018e4f1dc8;0;axis;Player1;01100001bfa8ff4c;1;allies;Player2;m4_fmj_mp;57;MOD_HEAD_SHOT;head
27:16 K;011000018e4f1dc8;0;axis;Player1;01100001bfa8ff4c;1;allies;Player2;m4_fmj_mp;57;MOD_HEAD_SHOT;head
27:45 D;011000018e4f1dc8;0;axis;Player1;01100001bfa8ff4c;1;allies;Player2;m4_fmj_mp;57;MOD_HEAD_SHOT;head
27:45 K;011000018e4f1dc8;0;axis;Player1;01100001bfa8ff4c;1;allies;Player2;m4_fmj_mp;57;MOD_HEAD_SHOT;head
[/php]

i want to ignore all words and and count the “K” string and “D” wich means K-Killed, D-Died.
i mean we have 2 players.

at first line:

27:16 D;011000018e4f1dc8;0;axis;Player1;01100001bfa8ff4c;1;allies;Player2;m4_fmj_mp;57;MOD_HEAD_SHOT;head

D(Died) - Player1 Died by Player2
secound line:
27:16 K;011000018e4f1dc8;0;axis;Player1;01100001bfa8ff4c;1;allies;Player2;m4_fmj_mp;57;MOD_HEAD_SHOT;head
K(Killed) - Player1 Killed Player2
at all i want just print totall Killes and deaths
like this Player1 - 2/2
Player name - Killes/Deaths.

thanks you very much.
also my php knowlage are not so good but i wish you can help me.
thank you for your time.

Not tested as it’s late and am going to bed now, but let me know if it doesn’t work and I’ll test it (though it should work).

[php]$data = file(‘data/yourtxtfile.txt’);
$players = array();
foreach($data as $info)
{
$info = explode(’;’,$info);
$pname1 = trim($info[4]);
$pname2 = trim($info[8]);
$action = explode(’ ',$info[0]);
$time = $action[0];
$type = strtolower($action[1]) == ‘k’ ? ‘kills’ : ‘deaths’;
if(!array_key_exists($pname1,$players))
{
$players[$pname1] = array();
$players[$pname1][‘kills’] = 0;
$players[$pname1][‘deaths’] = 0;
}
$players[$pname1][$type]++;
//If the one line needs to store the death for player1 and kill for player2 (there aren’t two lines for the same action)
if(!array_key_exists($pname2,$players))
{
$players[$pname2] = array();
$players[$pname2][‘kills’] = 0;
$players[$pname2][‘deaths’] = 0;
}
$opptype = $type == ‘kills’ ? ‘deaths’ : ‘kills’;
$players[$pname2][$opptype]++;
}

echo ‘

’;
print_r($players);
echo ‘
’;
[/php]

Thank you so much, this code working perfect but, there a spaces on each line so if i remove them on log its working aswell, so can it be with spaces?

by the way, there is not full log, in the log there alot of words that i want to ignore and use only these. its possible? i mean only Kills and deaths.

one more thing, its possible to make it by player name, like i want to print only where Player1 wich hes name “Azeroth”.

Thank you for your time Smokey, again.

Sponsor our Newsletter | Privacy Policy | Terms of Service