- scandir: documentation ( source)
- substr: documentation ( source)
- file_get_contents: documentation ( source)
- explode: documentation ( source)
<?php
$scandir = scandir('c:/keycounter');
$stats = array();
foreach($scandir as $filename){
if(substr($filename, -4) !== '.day') continue;
$date = substr($filename, 0, -4);
$stats[$date]= array('k' => 0, 'm' => 0);
$content = file_get_contents('c:/keycounter/'.$filename);
$lines = explode("\n", $content);
foreach($lines as $line){
if($line === '') {
continue;
}
$exp2 = explode(",", $line);
$stats[$date]['k']+=intval($exp2[0]);
$stats[$date]['m']+=intval($exp2[1]);
}
}