lazaruz Posted December 9, 2007 Share Posted December 9, 2007 I am trying to parse an apache logfile to count how many unique downloads I have of certain files. I have the lines parsed and read them one by one and and adds the line if it does not already exists in an array. if(stristr($parsed_line['path'], '.rar')) { $element = $parsed_line['ip'] . " " .$parsed_line['date'] . " " . $parsed_line['path']; if(stristr($parsed_line['path'], 'somefile1.rar')) if(Add($element, $arr1)) { $arr1[count($arr1)] = $element; } if(stristr($parsed_line['path'], 'somefile2.rar')) if(Add($element, $arr2)) { $arr2[count($arr2)] = $element; } } I test the lines with: function Add($element, $arr) { foreach($arr as $line) { if($line == $element) return false; } return true; } And print the result with: echo "Somefile1: " . count($arr1); echo "<br>"; echo "Somefile2: " . count($arr2); Now, this works but there must be a better way to do it. The way I'm doing it now results in that I have to create one array for each file I'm looking for and add a codeblock to add that specific file. I'm looking for a way to place all valid lines in one array and count them based on filename. This way I don't have to update the php-code if I add a new file to download. Link to comment https://forums.phpfreaks.com/topic/80864-parsing-an-apache-logfile/ Share on other sites More sharing options...
dsaba Posted December 9, 2007 Share Posted December 9, 2007 if you're having trouble parsing through something you might want to post this something, so we can see what went wrong when you parsed through it Link to comment https://forums.phpfreaks.com/topic/80864-parsing-an-apache-logfile/#findComment-410515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.