A cleaner way to do this?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am working on a parser for logs from a spam firewall. The format is
predictable until it reaches a certain point. It then varies greatly.

There are 2 things I want to grab from this area; the size of the
message (if it exists) and the subject (if it exists)

The line might look something like this:

- 2 39 some.text.here SZ:1825 SUBJ: A subject here

but it could also look like this:

5 6 421 Error: timeout

or this:

5 6 421 Client disconnected

All I really want is the value for each, not the prefix stuff. Which
means I still need more below, yuck.

I am doing it like this:

$remainder = explode(" ", $theLine, 18);
                $s_size = '/SZ:\d+/';
                $s_subject = '/SUBJ:.+/';

                preg_match("$s_size","$remainder[17]",$a);
                preg_match("$s_subject","$remainder[17]",$b);

                if (count($a) > 0) {
                    $size = $a[0];
                } else {
                    $size = 0;
                }

                if (count($b) > 0) {
                    $subject = $b[0];

                } else {
                    $subject = "-";
                }

Is there any way to clean this up a bit?

thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux