X-Original-To: pgsql-php@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3F3E4475B47 for ; Tue, 29 Apr 2003 15:15:30 -0400 (EDT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by postgresql.org (Postfix) with ESMTP id 45359475B47 for ; Tue, 29 Apr 2003 15:14:54 -0400 (EDT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h3TJDiF2010603; Tue, 29 Apr 2003 13:13:52 -0600 (MDT) Date: Tue, 29 Apr 2003 13:04:50 -0600 (MDT) From: "scott.marlowe" To: Cc: Subject: Re: New New :(( - Trying to figure out a couple things - Please In-Reply-To: <002101c30e80$2e89c750$a3b56644@marcottesamiam> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Spam-Status: No, hits=-29.6 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,NO_DNS_FOR_FROM, QUOTED_EMAIL_TEXT,REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/33 X-Sequence-Number: 2003 On Tue, 29 Apr 2003 sam@casheze.biz wrote: > Hi Sam Marcotte here > > I am real new at this - Old Mainframer and I know what I want to do but > just > not finding the correct functions. > > I want to figure out how to put info out of a file (it is xml). > > I need to find a way to look thru the file and find lines that look lik > Computers > I want to pull out just Computers (remove and write to another file (I > can do the writes) > > Then > Computers - ddddddd > dddddd > dddddd > ddddd > multi lies from start of desc to end - and take the off - and write > each > record till I find the end > > I know we are talking about 2 or 3 loops my main problem is find given data > in the middle > of a line of txt. There are really two ways to go about this, one is to write your own parser, the other is to let a library handle it for you. Most Linux boxes already have expat involved, and if they don't, it's easy to get. Check out the xml docs in the PHP documentation, particularly: xml_parse_into_struct and it's relatives. The other way, parsing it by hand, isn't as bad as all that. If the file isn't very big (say under a megabyte) then just read the whole thing in like so: $file="filename.xml"; $fp = fopen ($file,"r"); $body = fread($fp,filesize($file)); $lines = split ("\n",$body); foreach($lines as $line){ if (ereg("thingtomatch",$line)){ (parse a line here); } } For parsing a line, look at the regex and string functions. ereg is easier to grasp for most beginners than perl regexes. For a definition of posix regex, on most unix boxes you can type 'man 7 regex' or something like it to get a nice page explaining how they work. Something like: $a="This is a test"; if (eregi("",$a); $len = strlen($a); print substr($a,$start,$len-$end); } something like that.