<? $mem='Newsgroups: php.general Path: news.php.net Xref: news.php.net php.general:109465 Return-Path: <[EMAIL PROTECTED]> Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm Delivered-To: mailing list [EMAIL PROTECTED] Received1: (qmail 60843 invoked from network); 25 Jul 2002 10:36:29 -0000 Received: from unknown (HELO parker.comology.com) (213.187.218.7) by pb1.pair.com with SMTP; 25 Jul 2002 10:36:29 -0000 Received2: (qmail 14308 invoked by uid 500); 25 Jul 2002 10:36:27 -0000 Date: Thu, 25 Jul 2002 12:36:27 +0200 To: [EMAIL PROTECTED] Message-ID: <[EMAIL PROTECTED]> Reply-To: Nicklas af Ekenstam <[EMAIL PROTECTED]> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.28i X-Operating-System: Linux parker 2.4.10-4GB X-PGP-Key: http://nille.org/pubkey.txt Organization: comology.se Subject: Reg exp to remove line feeds before lines starting with white space From: [EMAIL PROTECTED] (Nicklas Af Ekenstam)
Hi Im trying to do some parsing of mail headers and since not all headers follow the pattern: '; $lines = split("\n", $mem); for ( $c = count($lines), $i=0, $headers = array(), $lastkey = 'x' ;$i<$c ;$i++) { $t = $lines[$i]; if (preg_match('/^([a-z].+?):\s*(.+)/i', $t, $result)) { $lastkey = $result[1]; $headers[$lastkey] = trim($result[2]); } else { $headers[$lastkey] .= "\n" . $t; } // end of headers? if (trim($t)=='') break; } while (list($key, $val) = each($headers)) echo "$key=$val\n"; ?> note: i have renamed headers with same name! like 'received' cause I don't know how you want to handle them! good luck, //elias "Nicklas Af Ekenstam" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Hi > > I'm trying to do some parsing of mail headers and since not all > headers follow the pattern: > > X-Header-A: A string > X-Header-B: Another string that is longer > X-Header-C: And this string is very very long compared > > But may very well look like this: > > X-Header-A: A string > X-Header-B: Another string that is > longer > X-Header-C: And this string is very very long > compared > > (Note that two of the header lines above wrap more than one line.) > > In order to read the headers into an array of header key/value fields > i would like a reg exp to remove all new lines/line feeds before a > line starting with one or more white spaces or tabs. > > I've tried myself but I'm just nog good with reg exps. > > > Thanks in advance, > Nicklas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php