JazzJackrabbit Community Forums

JazzJackrabbit Community Forums (http://www.jazz2online.com/jcf/index.php)
-   General Jazz Jackrabbit Talk (http://www.jazz2online.com/jcf/forumdisplay.php?f=4)
-   -   Parse the playlog (http://www.jazz2online.com/jcf/showthread.php?t=18216)

DanZeal Apr 17, 2009 02:25 PM

Parse the playlog
 
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 Code:

<?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


All times are GMT -8. The time now is 01:49 AM.

Powered by vBulletin® Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
JCF © 2001-Infinity Jazz2Online