程序 文件log.txt:
220.172.12.141  [17/Feb/2011:06:05:52 +0800] "GET /lift.sohu.com.cn/tuan.html"
220.172.12.142  [17/Feb/2011:06:05:54 +0800] "GET /lift.sohu.com.cn/ent.html"
220.172.12.143  [17/Feb/2011:06:05:55 +0800] "GET /lift.souhu'.com.cn/tuan.html"
220.172.12.144  [17/Feb/2011:08:05:56 +0800] "GET lift.sohu.com.cn/sports.html"
220.172.12.145  [17/Feb/2011:10:05:56 +0800] "GET lift.sohu.com.cn/news.html"
220.172.12.145  [17/Feb/2011:11:05:57 +0800] "GET lift.sohu.com.cn/tuan.html".
统计出各小时/lift.sohu.com.cn/tuan.html 的页面访问次数

解决方案 »

  1.   

    $text = '220.172.12.141  [17/Feb/2011:06:05:52 +0800] "GET /lift.sohu.com.cn/tuan.html"
    220.172.12.142  [17/Feb/2011:06:05:54 +0800] "GET /lift.sohu.com.cn/tuan.html"
    220.172.12.144  [17/Feb/2011:08:05:56 +0800] "GET lift.sohu.com.cn/sports.html"
    220.172.12.145  [17/Feb/2011:10:05:56 +0800] "GET lift.sohu.com.cn/news.html"
    220.172.12.145  [17/Feb/2011:11:05:57 +0800] "GET lift.sohu.com.cn/tuan.html"';
    $text改成 file_get_contents("log.txt");
    preg_match_all("/lift.sohu.com.cn\/tuan.html/",$text,$out);
    echo count($out[0]);
      

  2.   


    $data = <<<EOF
    220.172.12.141  [17/Feb/2011:06:05:52 +0800] "GET /lift.sohu.com.cn/tuan.html"
    220.172.12.142  [17/Feb/2011:06:05:54 +0800] "GET /lift.sohu.com.cn/ent.html"
    220.172.12.143  [17/Feb/2011:06:05:55 +0800] "GET /lift.souhu'.com.cn/tuan.html"
    220.172.12.144  [17/Feb/2011:08:05:56 +0800] "GET lift.sohu.com.cn/sports.html"
    220.172.12.145  [17/Feb/2011:10:05:56 +0800] "GET lift.sohu.com.cn/news.html"
    220.172.12.145  [17/Feb/2011:11:06:57 +0800] "GET lift.sohu.com.cn/tuan.html"
    220.172.12.145  [17/Feb/2011:11:07:57 +0800] "GET lift.sohu.com.cn/tuan.html"
    220.172.12.145  [17/Feb/2011:11:08:57 +0800] "GET lift.sohu.com.cn/tuan.html"
    220.172.12.145  [17/Feb/2011:11:09:57 +0800] "GET lift.sohu.com.cn/tuan.html"
    220.172.12.145  [17/Feb/2011:11:10:57 +0800] "GET lift.sohu.com.cn/tuan.html"
    220.172.12.145  [17/Feb/2011:11:11:57 +0800] "GET lift.sohu.com.cn/tuan.html"
    220.172.12.145  [17/Feb/2011:11:05:57 +0800] "GET lift.sohu.com.cn/tuan.html"
    220.172.12.145  [17/Feb/2011:11:05:57 +0800] "GET lift.sohu.com.cn/tuan.html"
    EOF;
    $temp = array ();
    preg_match_all ( '/\[([^\]]*)\] "GET lift.sohu.com.cn\/tuan.html"/', $data, $temp );
    $result = array ();
    foreach ( $temp [1] as $val ) {
    $hour = date ( 'G', strtotime ( $val ) );
    if (isset ( $result [$hour] )) {
    $result [$hour] += 1;
    } else {
    $result [$hour] = 1;
    }
    }
    var_dump($result);
      

  3.   

    这一句只取出小时么,对php刚接触