求一个简单的php

kobe00712 sina 服务器端工程师  2013-02-20 04:17:40
程序 文件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 的页面访问次数
...全文
114 4 点赞 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
kobe00712 2013-02-20
引用 3 楼 bbjbepzz 的回复:
PHP code?123456789101112131415161718192021222324252627$data = <<<EOF220.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 +08……
这一句只取出小时么,对php刚接触
  • 打赏
  • 举报
回复
bbjbepzz 2013-02-20

$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);
  • 打赏
  • 举报
回复
kobe00712 2013-02-20
引用 1 楼 zhangbin1988 的回复:
PHP code?12345678$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.ht……
没有实现按小时统计
  • 打赏
  • 举报
回复
ayzen1988 2013-02-20
$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.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
帖子事件
创建了帖子
2013-02-20 04:17
社区公告
暂无公告