p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

beginning_php thread: Parsing a Text file

Message #1 by "Srinivasan Prasanna" <Sri_Core@m...> on Mon, 22 Apr 2002 11:25:19 -0400
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am writing an application which shall parse through a text file and gra
b these values and put in a table form as an output. The test file is lik
e this
9321--03139-134912-943JDOIASJOPJDFSA;Test12@m...;21-093-21943 DNSANDFS
The output I require will be ID number (9321) SysID number (03139) CtrlID
 (943JDOIASJOPJDFSA) and the email ID (Test12@m...) .....

I would highly appreciate any help from anyone.
SriGet more from the Web.  FREE MSN Explorer download : http://explorer.m

Message #2 by "Nikolai Devereaux" <yomama@u...> on Mon, 22 Apr 2002 09:26:55 -0700
Hooray for regular expressions!  There's probably more efficient ways of
writing this expression, but it works (I think).

$patt = "/^(\d+)--(\d+)-[^-]+-([0-9A-Z]+);([^;]+);\d+.*$/";
$string = "9321--03139-134912-943JDOIASJOPJDFSA;Test12@m...;21-093-21943

preg_match($patt, $string, $matches);

$id     = $matches[1];
$sysid  = $matches[2];
$ctrid  = $matches[3];
$email  = $matches[4];


  Return to Index