Jump to content

Help parsing HTML log file


mrmagoo_83

Recommended Posts

Ok, I know hardly anything about php code, but I have worked with it a little.

I have an html log file that is a compilation of chat events on our server.

I need to create a script that will evaluate the log file, and return entire lines that contain certain strings. We are examing the log file for rule violations.

ex.
[code]<tr><td>[08/08/2006 04:43:37]</td><td><FONT color="#254117">[P.A.K]DarkPrince</FONT></td><td><FONT COLOR="#000000">[DEFENSE] :D</FONT></td></tr>
<tr><td>[08/08/2006 04:44:18]</td><td><FONT color="#FF0000">[P.A.K]DarkPrince</FONT></td><td><FONT COLOR="#000000">[DEFENSE] :D:D:D</FONT></td></tr>
<tr><td>[08/08/2006 04:44:19]</td><td><FONT color="#254117">SentinalAtArms</FONT></td><td><FONT COLOR="#000000">[ASSAULT] :D</FONT></td></tr>
<tr><td>[08/08/2006 04:45:28]</td><td><FONT color="#FF0000">[P.A.K]DarkPrince</FONT></td><td><FONT COLOR="#000000">[DEFENSE] camper:(</FONT></td></tr>[/code]

I want the script to run such that if I search for "Dark" I would get the return of:
[code]<tr><td>[08/08/2006 04:43:37]</td><td><FONT color="#254117">[P.A.K]DarkPrince</FONT></td><td><FONT COLOR="#000000">[DEFENSE] :D</FONT></td></tr>
<tr><td>[08/08/2006 04:44:18]</td><td><FONT color="#FF0000">[P.A.K]DarkPrince</FONT></td><td><FONT COLOR="#000000">[DEFENSE] :D:D:D</FONT></td></tr>
<tr><td>[08/08/2006 04:45:28]</td><td><FONT color="#FF0000">[P.A.K]DarkPrince</FONT></td><td><FONT COLOR="#000000">[DEFENSE] camper:(</FONT></td></tr>[/code]

It doesn't have to be caps sensitive, and the return page would actually be in html so I would see the tags, but just the wording.

Can anyone help me even start to understand to how to begin this script.

Link to comment
https://forums.phpfreaks.com/topic/17027-help-parsing-html-log-file/
Share on other sites

It doesn't look like you're parsing anything, but merely searching for lines that contain values.

Call this as [tt]perl name_of_log_file.log[/tt].

[code]
#!/usr/bin/perl
use warnings;
use strict;
while (<>) {
print if /Dark/;
}
[/code]

If you get that working, the hard coding can be removed.

Actually, if this doesn't get much more complex, use Unix's [b]grep[/b] command: [tt]grep Dark name_of_log_file.log[/tt].
[code=php:0]
$search = "dark";
$data = //(do Fread stuff here to get your log file);
$pieces = explode("\n",$data);
$count = count($pieces);
for ($i=0;$i<=$count;$i++){
if (strpos($pieces[$i], $search){
echo "$pieces[$i]<br>/n";
}
}[/code]
[hr]
I haven't tested this, as I'm just writing it in QuickReply, but something along those lines should work.
Fread stuff? I am not sure what you are referring to, however, the rest of your code was what I was examing earlier, or at least something similar.

Now my other question is how the heck do I get this to execute on my webpage, lol, like I said I am newbish to all this, I usually deal with editing prexisting php code and such.
#!/usr/bin/perl




$search = "dark";
$lines_of_file = file('http://63.210.148.20/63.210.148.20/CL-Current.html');
foreach ($lines_of_file as $line) {
if (strstr($line, $search)) {
  echo $line;
}
}


However, I get an internal server error, any thoughts?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.