A cleaner way to do this?

From: Date: Thu, 25 Mar 2010 16:42:36 +0000
Subject: A cleaner way to do this?
Groups: php.general 
Request: Send a blank email to php-general+get-303454@lists.php.net to get a copy of this message
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.

« previous php.general (#303454) next »