- preg_match: documentation ( source)
- print_r: documentation ( source)
<?php
$pattern = '/(?P<hostname>[\w\.]+) '
. '(?P<forwardedFor>(?:[\d\.]+, )*(?:[\d\.]+)|-) '
. '(?P<remoteHostname>[\d\.]+) '
. '(?P<remoteLogname>[^\s]+) '
. '(?P<remoteUsername>[^\s]+) '
. '\['
. '(?P<requestDate>[^\]]+)'
. '\] '
. '"'
. '(?P<method>\w+) '
. '(?P<uri>[^\s]+) '
. '(?<httpVersion>[^\"]+)'
. '" '
. '(?P<responseStatus>\d+) '
. '(?P<responseSize>\d+)/';
$test = 'my.server.com 24.24.24.3, 1.2.3.4 1.2.3.5 - - [18/May/2016:02:57:25 -0400] "GET /veer/eye?params=1&are=2&right=3&here=4 HTTP/1.1" 200 146351';
$test2 = 'qa-test.test.com - 80.82.65.120 - - [18/May/2016:00:30:20 -0400] "GET // HTTP/1.1" 404 198';
preg_match($pattern, $test, $matches);
print_r($matches);
preg_match($pattern, $test2, $matches);
print_r($matches);