Jump to content

gregp

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

gregp's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks! :) Knew it would be something pretty straightforward. Went with the substr option and works a treat! Incidentally there are several different strings the log file may contain and these are in an if else loop with a generic message in the else statement at the end to catch anything unexpected. Thanks for your time!
  2. Hi guys, I'm fairly new to PHP which the question probably suggests! :) I'm sure this is not difficult at all but I'm obviously missing one step. I have a script which examines a log file and generates HTML based on the information in that logfile. The start of the log file looks as follows: # NetSaint 0.0.7b7 Status File [1158624594] PROGRAM;1158131198;18534;0;ACTIVE;1158131199;1158624579;1158417000;1;1;1;0;0 [1158624594] HOST;aarnet;UP;1158580409;1158448819;0;317427;189;0;0;0;1;1;1;1;0;0.00;0;PING OK - Packet loss = 0%, RTA = 0.57 ms To get the status for aarnet for example, I store HOST;aarnet;UP in a variable such as aarnet_OK and use the following code to check whether there's a match anywhere in the line presently under review, and to set a flag if it finds it: if (strpos($line, $aarnet_OK))  { $aarnet_status = 'OK'; } to get the status flag. That works, though it's a bit messy. I would prefer to extract the text 'up' from the logfile and use that. The situation now is that I want to display the datestamp of the logfile, which is the string of characters in the first line. Obviously this will change every minute so I can't use the above code to do that - I need to do exactly what I originally wanted, that is, extract the 10 digit character and store it in a variable. Incidentally this same string appears at the start of every of the 400 lines in the logfile so it would be nice to be able to specify just one line to do this extraction on rather than running it on every single line of the log file. The code above is within the following code: $fp = fopen('status.log', 'r'); $strings = array(); while(!feof($fp)){ $line = fgets($fp); Can someone please, after groaning at how simple this request is, show me what code I should use for that? I figure it may be preg_match or something along those lines but haven't had any suggess so far. Thanks in anticipation! Greg
×
×
  • 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.