mrmagoo_83 Posted August 9, 2006 Share Posted August 9, 2006 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. Quote Link to comment Share on other sites More sharing options...
effigy Posted August 9, 2006 Share Posted August 9, 2006 I would use Perl for this. Are you restricted to PHP? Quote Link to comment Share on other sites More sharing options...
mrmagoo_83 Posted August 9, 2006 Author Share Posted August 9, 2006 Nope, I just figured php since it was something I had seen RSS/XML parsers before.Any suggestions on how to do it in Perl? Quote Link to comment Share on other sites More sharing options...
effigy Posted August 9, 2006 Share Posted August 9, 2006 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/perluse 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]. Quote Link to comment Share on other sites More sharing options...
alexruimy Posted August 9, 2006 Share Posted August 9, 2006 [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. Quote Link to comment Share on other sites More sharing options...
mrmagoo_83 Posted August 9, 2006 Author Share Posted August 9, 2006 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. Quote Link to comment Share on other sites More sharing options...
effigy Posted August 9, 2006 Share Posted August 9, 2006 Use [tt]file[/tt] to read the lines into an array; don't worry about [tt]fread[/tt]. Quote Link to comment Share on other sites More sharing options...
mrmagoo_83 Posted August 9, 2006 Author Share Posted August 9, 2006 Still lost, sorry :( Quote Link to comment Share on other sites More sharing options...
effigy Posted August 9, 2006 Share Posted August 9, 2006 [code]$lines_of_file = file('log_file');foreach ($lines_of_file as $line) { if (strstr($line, 'Dark')) { echo $line; }}[/code] Quote Link to comment Share on other sites More sharing options...
mrmagoo_83 Posted August 9, 2006 Author Share Posted August 9, 2006 #!/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? Quote Link to comment Share on other sites More sharing options...
effigy Posted August 9, 2006 Share Posted August 9, 2006 I posted PHP not Perl, since you didn't respond about the Perl. Don't use the [tt]#!/usr/bin/perl[/tt] line. Why do you use the IP address twice? Quote Link to comment Share on other sites More sharing options...
mrmagoo_83 Posted August 10, 2006 Author Share Posted August 10, 2006 Thanks so much. I got it to work great. 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.