1. Go to this page and download the library: Download mvar/apache2-log-parser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mvar / apache2-log-parser example snippets
Var\Apache2LogParser\AccessLogParser;
// Access log format from your Apache configuration
// It can be any of predefined `AccessLogParser::FORMAT_*` constants or custom string
$parser = new AccessLogParser('%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"');
// String which you want to parse
$line = '66.249.78.230 - - [29/Dec/2013:16:07:58 +0200] "GET /my-page/ HTTP/1.1" 200 2490 "-" ' .
'"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"';
var_export($parser->parseLine($line));
Var\Apache2LogParser\AccessLogParser;
use MVar\LogParser\LogIterator;
$parser = new AccessLogParser(AccessLogParser::FORMAT_COMMON);
foreach (new LogIterator('access.log', $parser) as $line => $data) {
printf("%s %s\n", $data['request']['method'], $data['request']['path']);
}
$parser = new AccessLogParser(AccessLogParser::FORMAT_COMMON);
// Set custom date and time format accepted by date()
$parser->setTimeFormat('Y-m-d H:i:s');
// Set TRUE and you will get \DateTime object
$parser->setTimeFormat(true);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.