Re: A cleaner way to do this?

From: Date: Thu, 25 Mar 2010 16:48:15 +0000
Subject: Re: A cleaner way to do this?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-303455@lists.php.net to get a copy of this message
On 25 March 2010 16:42, Paul Halliday <paul.halliday@gmail.com> wrote: > 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 > > You can do it handraulically using string functions. You can also use regular expressions. If you can supply a sensible chunk, I can build a regex for you. Indicate the exact elements you want to retrieve. If you want to email me the log file directly that's fine. -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling

« previous php.general (#303455) next »