<?php
/*
date:04-28 time:09:23:52 thread:[Thread-2] status :DEBUG
*/
$file = '1.txt';
$fp = fopen($file, 'r');
$tmp = array();
while (!feof($fp)) {
$t = fgets($fp);
preg_match_all('/date:\s*([0-9\-]+)\s*time:\s*([0-9:]+)\s*thread:\s*\[([A-Za-z0-9\-]+)\]/i', $t, $m);
$date = $m[1][0];
$thread = $m[3][0];
$tmp[$date][$thread]++;
}print_r($tmp);
?>
/*
date:04-28 time:09:23:52 thread:[Thread-2] status :DEBUG
*/
$file = '1.txt';
$fp = fopen($file, 'r');
$tmp = array();
while (!feof($fp)) {
$t = fgets($fp);
preg_match_all('/date:\s*([0-9\-]+)\s*time:\s*([0-9:]+)\s*thread:\s*\[([A-Za-z0-9\-]+)\]/i', $t, $m);
$date = $m[1][0];
$thread = $m[3][0];
$tmp[$date][$thread]++;
}print_r($tmp);
?>
$container = array();
$filepath = './csdn.txt';
if (file_exists($filepath))
{
$fp = fopen($filepath, r);
while (!feof($fp))
{
$aline = fgetss($fp);
$thread = substr($aline, 33, 8);
$container[$thread] += 1;
}
print_r($container);
}
else
{
return false;
}
按楼主要求,以下代码绝对正解:
<?php
$f = file("test.txt");
$count = array();foreach ($f as $line) {
eregi("date:(.+) time:.*",$line,$e);
if(isset($count[$e[1]])) $count[$e[1]] += 1;
else $count[$e[1]] = 1;
}
foreach($count as $key => $line){
echo $key . ":" . $line . "<br>";
}
?>