Splitting a Log into a 3D array
12
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:
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;
}






Anywhoo, this is a nice, lightweight parser, and I'm sure it does what you set out to do (or you wouldn't post it). A little inflexible for my taste, but I tend to prefer a great generality of function in parsers. Still, you've got my upvote.
Cheers!
I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?