Created
August 17, 2016 16:13
-
-
Save kaynenh/12404ad615ee591462798fe6edea93e3 to your computer and use it in GitHub Desktop.
Use Regex to create CSV of raw access logs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
^(.+).log(?:\.(?:\d+))?(?:\.gz)?\:((?:\d|\.)+)\s-\s-\s\[((?:\d{2})\/(?:\w{3,4})\/(?:\d{4})):(\S+)\s\+(?:\d+)\]\s\"GET \/wp-content\/uploads\/(?:mp3s\/)?(\S+)\s\S+\s(\d{3})\s\d+\s\S+\s\"(.*)\"$ | |
*/ | |
$re = "/^(.+).log(?:\\.(?:\\d+))?(?:\\.gz)?\\:((?:\\d|\\.)+)\\s-\\s-\\s\\[((?:\\d{2})\\/(?:\\w{3,4})\\/(?:\\d{4})):(\\S+)\\s\\+(?:\\d+)\\]\\s\\\"GET \\/wp-content\\/uploads\\/(?:mp3s\\/)?(\\S+)\\s\\S+\\s(\\d{3})\\s\\d+\\s\\S+\\s\\\"(.*)\\\"$/mi"; | |
$file = file_get_contents('search_results.txt'); | |
preg_match_all($re, $file, $matches, PREG_SET_ORDER); | |
foreach($matches as $match) { | |
$comma_separated = implode("`,`", $match); | |
echo '`'.$comma_separated . "`<br />"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment