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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.