This is more a conceptual problem rather than a specific PHP problem. I have to be honest, I'm not actually writing the program in PHP, but I could be.
Right, here's the deal.
Reading in lines form a log file. If you're interested they're holding logs generated by iptables.
I am reading the file in char by char and need a way of determining whether the line I'm currently on is one that I want to looking at, this is fine for the date time part I can just say "do the first 16 lines match the regex "/[A-Z][a-z]{2}\s[0-9]\s[0-9]{2}:[0-9]{2}:[0-9]{2}\s"" but but all lines should match that and if they don't there's somthing going wrong in the loggin system.
The next parameter would be the machine name but this is not a known size so we cannot restrict by size. I guess we could skip along to another stage once the date info has been matched but this seems like unecesarry work. Here is a rough idea of what I'm doing so far.
define('NEWLINE',"\n");
$line="";
$skip_line=false;
$file = new FileReader('log_file');
while($file->current_pos < $file->FILE_SIZE) {
$c = $file->getChar();
if($c == NEWLINE) {
$line = "";
$skip_line=false;
continue;
} else if ($skip_line==true) {
continue;
} else {
$line+=$c;
if(strlen($line) == 16 && !preg_match('/^[A-Z][a-z]{2}\s{1,2}[0-9]{1,2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}$/',$line)) {
$skip_line=true;
}
}
}
That's as far as I've got and I'm a little stuck.
Thanks in advance
Bubble