Splitting a Log into a 3D array





12
Date Submitted Mon. Oct. 9th, 2006 8:18 AM
Revision 1 of 1
Helper shell
Tags PHP
Comments 1 comments
Over the summer, I worked on a project in which I needed to parse logfiles which were in the following format:

IP|USE|TIME>IP2|USE2|TIME2>

and so on.

When I parsed them to display the log file in a user-friendly fashion, I used the following code:

$myfile = "FILE NAME HERE";
if(filesize($myfile) == 0) {
        die("");
}

$handle = fopen($myfile, "r");
$mycont = fread($handle, filesize($myfile));
fclose($handle);
          
$mycont[strlen($mycont) - 1] = "";
          
$splitd = split(">", $mycont);
$i = 0;
          
foreach($splitd as $value) {
     $arr[$i] = explode("|", $value);
     $i = $i + 1;
}
          
$n = $i;
$i = 0;
          
while($i != $n) {
     // use whatever way you want to print your code
     $i = $i + 1;
}
 

Comments

Comments Oooo . . . a parser!
Mon. Oct. 9th, 2006 8:40 AM    Scripter sehrgut

Voting