DanZeal
Apr 17, 2009, 02:25 PM
Need help to parse the playlog file so it can be submited to a mysql database.
If anyone got some knowledge in this please tell me.
Some progress has already been made with the php code.
djazz
Oct 22, 2009, 05:16 AM
<?php
// Parse each log from playlog001.txt
$file='./playlog001.txt';
$playLog=array_slice(explode("
[[",file_get_contents($file)),1);
$playArray=array();
$playLength=count($playArray);
foreach($playLog as $key => $value) {
$playLog[$key]=explode('
',$playLog[$key]);
array_pop($playLog[$key]);
$playLog[$key][0]=preg_replace("/(\w+), (\w+) (\d)(\d), (\d)(\d)(\d)(\d) at (\d)(\d):(\d)(\d):(\d)(\d)\]\]/","$1 $2 $3$4, $5$6$7$8 - $9$10:$11$12:$13$14",$playLog[$key][0]);
$playLog[$key][1]=preg_replace("/\*\*Current level: \"(.*?)\" - (.*?)/","$1 | $2",$playLog[$key][1]);
$playLog[$key][2]=preg_replace("/\*\*Next level: (.*?)/","$1",$playLog[$key][2]);
$playLog[$key][3]=preg_replace("/\*\*Game Mode: /","",$playLog[$key][3]);
$customMode=preg_replace("/\*\*Custom Mode: /","",$playLog[$key][4]);
if($customMode!='OFF'){
$playLog[$key][3]=$customMode;
//echo $playLog[$key][3];
}
//$playLog[$key][4]=preg_replace("/\[(\d)(\d):(\d)(\d):(\d)(\d)\] >>> Game Start/","$1$2:$3$4:$5$6",$playLog[$key][5]);
$line=0;
$endLine=0;
for($i=5;$i < count($playLog[$key]);$i++) {
if(strchr($playLog[$key][$i],"*** Game End Stats")){
$playLog[$key][4]=preg_replace("/\*\*\* Game End Stats \[\[(\w+), (\w+) (\d)(\d), (\d)(\d)(\d)(\d) at (\d)(\d):(\d)(\d):(\d)(\d)\]\] \*\*\*/","$1 $2 $3$4, $5$6$7$8 - $9$10:$11$12:$13$14",$playLog[$key][$i]);
$line=$i+1;
}
if($line > 0 && ($i >= $line) && ($i < count($playLog[$key]))) {
$tmp=preg_replace("/( +) /"," | ",$playLog[$key][$i]);
$playLog[$key][$i]="";
$playLog[$key][$i-$line+5]=trim($tmp,' |
');
$endLine=$i-6;
}
else {}
}
if($endLine > 0) {
//$playLog[$key][count($playLog[$key])]="lol";
$playLog[$key]=array_slice($playLog[$key],0,$endLine);
}
}
print_r($playLog);
?>
Made this some time ago, not working fully yet.
Do whatever you want with it :D
vBulletin® v3.8.2, Copyright ©2000-2025, Jelsoft Enterprises Ltd.