Re: preg_match

From: Date: Wed, 14 Apr 2004 13:04:57 +0000
Subject: Re: preg_match
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-183308@lists.php.net to get a copy of this message
From: "Sorry Confidential" <sorry_confidential@hotmail.com> > I'm trying to parse a Postfix queue file to extract a few informations. The > Postfix queue file is a binary file. > > Here is an extract of the file, not a line, just an extract: > N^WFrom: <digital@sex.com>N^[To: <user@domain.com>N#Subject: Test 14 > 2004-04-13 15:13N%Date: Tue, 13 Apr 2004 15:13:35 -0400 > > $line is obtained with an fread > > if (preg_match('/To:.<(.+)>/',$line,$match)){ > print "To= $match[1]"; > } > > I get: > To= <user@domain.com>N#Subject: Test 14 2004-04-13 15:13N%Date: Tue, 13 > Apr 2004 15:13:35 -0400 > > I was expecting: > To= user@domain.com Try preg_match('/To:.<([^>]+)>/',$line,$match) Also, if you need to match more than one "to" at a time, look at preg_match_all(). Depending on the size of the file, it may be more efficient to read the entire file and match all of these at once. ---John Holmes...

« previous php.general (#183308) next »