求一个简单的php

kobe00712 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 的页面访问次数
...全文
165 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
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]);

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧