Im new to php been at it for a couple of weeks. Im a bit stuck I was going to take on a project to parse my custom apache log into a readable format and output it to a html page.
text file format is like this
[07/Jun/2002:21:56:35 +0000]syncalot.com /scripts/root.exe 66.28.236.41 279 - -
Date - Domain, url, ip of user, # of hits, user agent and something else,
the text file can get huge so Im not sure If i read it all in at first then try to parse it.
the way im going about it and this could totally be the wrong direction is to
first open the file
$FILEPATH = "/usr/local/apache/logs/cgic.log";
$FILE = fopen($FILEPATH, "r");
$contents = fread($FILE, filesize($FILEPATH));
fclose ($FILE);
Store the file into $contents
which when i print contents it prints out the whole file i think but of course this isnt very readable.
then i want to store each line in the text file into an array by looking for the \n end of line
$Array = explode ("\n",$contents);
$NewList = implode ("<BR>", $Array);
$keywords = preg_split("/[\s,]+/", $NewList);
some code might be extraous but im trying, i sorta do the try it and see appoach some stuff gets left in thats not being used.
now I run this though a loop to print out the results of the whole file.
for ($n = 0; $n <= count($Array); $n++)
{
$stuff = each($keywords);
$number = each($Array);
$DATE = substr($stuff[0], 1);
print ("String # $number[key] String: $number[value]<BR>");
$URL = ("www.$keywords[2].$keywords[3]");
}
ok so far so good, i got it printing out each line giving me the Key and Value of the array based upon the count of the original array, I THINK 🙂
now my question is how do i break up each line further into parts.
so $number[0] prints this:
String # 0 String: [07/Jun/2002:21:56:35 +0000] syncalot.com /scripts/root.exe 66.28.236.41 279 - -
what I want is to break up that line even further into a array..
and have it display the string like htis
Date: [07/Jun/2002:21:56:35 +0000]
Domain: syncalot.com
URL: $domain.scripts/root.exe
IP: 66.28.236.41
etc etc. and have that run though a loop processing each string stored in $number.
eventually i would like to create a nice table in html for the output, be able to sort the file by date,ip,domain,etc and since my webserver runs virtual host the log file includes several differnt domains, so it would be nice to maybe have a pull down menu to choose which domain to display etc. but one thing at a time..
ideas ? suggestions?
Gateway