php 匹配apache日志日期的代码
发布时间:2016-10-27 编辑:jiaochengji.com
教大家如何用php代码提取出apache日志中日期的方法,代码很简单,适合初学的朋友参考。
以下代码可用于匹配apache日志中的日期,然后得到类似:17 Dec 06 03:26:49 -0500的返回结果。
php得到apache日志中的日期,如下:
<?php // Set the default timezone to US/Eastern time: date_default_timezone_set('US/Eastern'); // Simulate reading an Apache log file, with the following line: $logline = '127.0.0.1 - - [17/dec/2006:00:26:49 -0800] "GET / HTTP/1.1" 200 41228'; // Since we only want the date section, use regex to obtain it: preg_match('/\[(.*?)\]/', $logline, $matches); // Take the date, and convert it: $timestamp = strtotime($matches[1]); // Now echo it out again to ensure that we read it correctly: echo date(DATE_RFC822, $timestamp); ?>
您可能感兴趣的文章:
php 匹配apache日志日期的代码
分析apache日志中蜘蛛爬行记录数量的shell脚本(图文)
Laravel 集成的 Monolog 库对日志进行配置和记录实例
php匹配图片地址的代码一例
删除及设置linux日志笔记
PHP正则匹配日期和时间(时间戳转换)的例子
PHP错误日志的使用及汇总
MySQL数据库二进制日志备份和恢复步骤
php 获取百度收录和百度快照时间的代码
mysql中删除二进制日志文件释放磁盘空间
[关闭]