/ Published in: PHP

I written this code to parse apache log in common log formats. It may have problems with irresponsible formatting like non-concluded into quotes request line. I welcome any modifications to my snippet because it was written if short time and this is my first snippet I publish here. Thanks.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function parse_access_log_line($format, $line) { // Get list of consistent patterns // Shift format string } // Add beginning of the string to the first pattern and end to the last $patterns[$keys[0]] = '^'.$patterns[$keys[0]]; // Consistently apply patterns to the log line shifting it to the right foreach ($patterns as $node => $pattern) { $result[$node] = $matches[2]; } return $result; }
Comments
