php程序重要是正则协助 很急很
程序员文章站
2022-06-09 19:59:09
...
php程序主要是正则协助 很急很急
文件log.txt:
220.172.12.141 [17/Feb/2011:06:05:52 +0800] "GET /lift.sina.com.cn/tuan.html"
220.172.12.142 [17/Feb/2011:06:05:54 +0800] "GET /lift.sina.com.cn/ent.html"
220.172.12.143 [17/Feb/2011:06:05:55 +0800] "GET /lift.sina.com.cn/tuan.html"
220.172.12.144 [17/Feb/2011:08:05:56 +0800] "GET lift.sina.com.cn/sports.html"
220.172.12.145 [17/Feb/2011:10:05:56 +0800] "GET lift.sina.com.cn/news.html"
220.172.12.145 [17/Feb/2011:11:05:57 +0800] "GET lift.sina.com.cn/tuan.html"
.
要求用php程序统计出各小时/lift.sina.com.cn/tuan.html 的页面访问次数
$hours = array();
$handle = fopen('log.txt','r+');
if ($handle){
while (!feof($handle)){
$line = fgets($handle,4096);
preg_match('/\d*\.\d*\.\d*\.\d* \[.*:(.*):.*:.* \+0800\] .*"GET\s\/lift\.sina\.com\.cn\/tuan\.html"/', $line,$result);
if (isset($result[1])){
$hours[$result[1]]++;
}
}
}
var_dump($hours);
我是用一个正则分组去做,为什么匹配不出时间
很急 很急
------解决方案--------------------
你那个也是对的,只是你忽略了
220.172.12.145 [17/Feb/2011:11:05:57 +0800] "GET lift.sina.com.cn/tuan.html"
中的是
GET lift.sina.com.cn/tuan.html
而不是
GET /lift.sina.com.cn/tuan.html
------解决方案--------------------
$handle = fopen('log.txt','r+');
echo $handle ; //看看读出来对不对
------解决方案--------------------
不存在你说的现象
文件log.txt:
220.172.12.141 [17/Feb/2011:06:05:52 +0800] "GET /lift.sina.com.cn/tuan.html"
220.172.12.142 [17/Feb/2011:06:05:54 +0800] "GET /lift.sina.com.cn/ent.html"
220.172.12.143 [17/Feb/2011:06:05:55 +0800] "GET /lift.sina.com.cn/tuan.html"
220.172.12.144 [17/Feb/2011:08:05:56 +0800] "GET lift.sina.com.cn/sports.html"
220.172.12.145 [17/Feb/2011:10:05:56 +0800] "GET lift.sina.com.cn/news.html"
220.172.12.145 [17/Feb/2011:11:05:57 +0800] "GET lift.sina.com.cn/tuan.html"
.
要求用php程序统计出各小时/lift.sina.com.cn/tuan.html 的页面访问次数
$hours = array();
$handle = fopen('log.txt','r+');
if ($handle){
while (!feof($handle)){
$line = fgets($handle,4096);
preg_match('/\d*\.\d*\.\d*\.\d* \[.*:(.*):.*:.* \+0800\] .*"GET\s\/lift\.sina\.com\.cn\/tuan\.html"/', $line,$result);
if (isset($result[1])){
$hours[$result[1]]++;
}
}
}
var_dump($hours);
我是用一个正则分组去做,为什么匹配不出时间
很急 很急
------解决方案--------------------
你那个也是对的,只是你忽略了
220.172.12.145 [17/Feb/2011:11:05:57 +0800] "GET lift.sina.com.cn/tuan.html"
中的是
GET lift.sina.com.cn/tuan.html
而不是
GET /lift.sina.com.cn/tuan.html
------解决方案--------------------
$handle = fopen('log.txt','r+');
echo $handle ; //看看读出来对不对
------解决方案--------------------
不存在你说的现象
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
上一篇: MySQL怎么样实现多个表的或查询?
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论