pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
New New :(( - Trying to figure out a couple things - Please help
3+ messages / 3 participants
[nested] [flat]

* New New :(( - Trying to figure out a couple things - Please help
@ 2003-04-29 15:54  marcottec@cox.net
  0 siblings, 0 replies; 3+ messages in thread

From: marcottec@cox.net @ 2003-04-29 15:54 UTC (permalink / raw)
  To: pgsql-php

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
 <d:Title>Computers</d:Title>
I want to pull out just Computers (remove <?> and write to another file (I
can do the writes)

Then
<d:Description>Computers - ddddddd
dddddd
dddddd
ddddd</d:Description>
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.

Thanks for any help




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* New New :(( - Trying to figure out a couple things - Please help
@ 2003-04-29 18:50  sam@casheze.biz
  0 siblings, 1 reply; 3+ messages in thread

From: sam@casheze.biz @ 2003-04-29 18:50 UTC (permalink / raw)
  To: pgsql-php

  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
  <d:Title>Computers</d:Title>
 I want to pull out just Computers (remove <?> and write to another file (I
 can do the writes)

 Then
 <d:Description>Computers - ddddddd
 dddddd
 dddddd
 ddddd</d:Description>
 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.

 Thanks for any help




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: New New :(( - Trying to figure out a couple things - Please
@ 2003-04-29 19:04  scott.marlowe <scott.marlowe@ihs.com>
  parent: sam@casheze.biz
  0 siblings, 0 replies; 3+ messages in thread

From: scott.marlowe @ 2003-04-29 19:04 UTC (permalink / raw)
  To: sam@casheze.biz; +Cc: pgsql-php

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
>   <d:Title>Computers</d:Title>
>  I want to pull out just Computers (remove <?> and write to another file (I
>  can do the writes)
> 
>  Then
>  <d:Description>Computers - ddddddd
>  dddddd
>  dddddd
>  ddddd</d:Description>
>  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="<A HREF='test.html'>This is a test</A>";
if (eregi("<a",$a)) {
  print "Found the start at ";
  $start = strpos("<A",$a);
  $end = strpos("</A>",$a);
  $len = strlen($a);
  print substr($a,$start,$len-$end);
}

something like that.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2003-04-29 19:04 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-04-29 15:54 New New :(( - Trying to figure out a couple things - Please help marcottec@cox.net
2003-04-29 18:50 New New :(( - Trying to figure out a couple things - Please help sam@casheze.biz
2003-04-29 19:04 ` Re: New New :(( - Trying to figure out a couple things - Please scott.marlowe <scott.marlowe@ihs.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox