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
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].
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

#!/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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.