Skip to content

Instantly share code, notes, and snippets.

@axiixc
Created May 7, 2011 21:12
Show Gist options
  • Save axiixc/960843 to your computer and use it in GitHub Desktop.
Save axiixc/960843 to your computer and use it in GitHub Desktop.
Quick and dirty, but it works. Scans your minecraft's server.log file and pulls out some stats.
<?php # axiixc.com
$file = 'server.log';
$contents = file($file);
$regexp_arr = array(
'message' => '/] <([A-Za-z0-9]+)>/',
'login' => '/] ([A-Za-z0-9]+) \[/',
'give' => '/] [A-Za-z0-9]+: Giving ([A-Za-z0-9]+) some/'
);
foreach ($regexp_arr as $argname => $regexp) {
$mMatches = array();
foreach ($contents as $line) {
if (preg_match($regexp, $line, $matches)) {
$mMatches[$matches[1]]++;
}
}
printf("-- %s --\n", $argname);
arsort($mMatches);
foreach ($mMatches as $userName => $count) {
printf("%5d\t%s\n", $count, $userName);
}
print("\n\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment