php-windows Digest 26 Sep 2006 18:51:00 -0000 Issue 3044
Topics (messages 27177 through 27180):
Re: Problems with fscanf [WORKAROUND] fgetc
27177 by: German Piqué
27180 by: Stanislav Malyshev
Re: Problems with fscanf
27178 by: Niel Archer
27179 by: German Piqué
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Well, I managed to work with the spaces but using fgetc instead of fscanf.
Scanning char by char, i haven't need to worry about the spaces or new
lines.
2006/9/26, German Piqué <[EMAIL PROTECTED]>:
Hello.
I'm trying to parse some XML files to get all in only one file, deleting
the first and last tag when needed. But when i try to read a line like this:
<ARTIST>The Communards</ARTIST>
with the code line:
fscanf($fr,"%s")
the output is the following:
<ARTIST>The
And i want to retrieve all the line without doing something like this:
fscanf($fr,"%s/t%s")
Because I have to adapt this line to the maximum spaces existing in a line
of the file... There isn't another better solution? Thank you :)
--- End Message ---
--- Begin Message ---
German Piqué wrote:
Well, I managed to work with the spaces but using fgetc instead of fscanf.
Just as a note I think it would be much more efficient to use fgets or
fread and then parse resulting string using regular expressions. Unless
you have some limitations that weren't mentioned.
--- End Message ---
--- Begin Message ---
Hi
First, if you're parsing XML files, I'd suggest using the XML modules to
do so.
I'm not sure what you're attempting. From the line:
<ARTIST>The Communards</ARTIST>
are you trying to retrieve all of it, or just "The Communards"? If the
latter then try a regex and not fscanf
This is a little loose on the tag matching but should do the job:
$pattern = '/<\w+>(.+)<\/\w+>/';
preg_match($pattern, $line, $matches);
returning the untagged data into $matches[1] and the tagged data into
$matches[0]
This assumes that you have only a single tagged entry per line.
Niel
--- End Message ---
--- Begin Message ---
All of it :P
I only want to delete the initial and final tags in order to unify various
archives with the sames patterns. To work with this archives I need to put
it one by one, so I thought that I can unify all in only one archive. I'm
doing it in php for my partners, because i'm not the only one with the
problem so i want this utility to work in any pc.
But i managet to solve this with fgetc :) See my other mail :)
Thanks anyway
2006/9/26, Niel Archer <[EMAIL PROTECTED]>:
Hi
First, if you're parsing XML files, I'd suggest using the XML modules to
do so.
I'm not sure what you're attempting. From the line:
<ARTIST>The Communards</ARTIST>
are you trying to retrieve all of it, or just "The Communards"? If the
latter then try a regex and not fscanf
This is a little loose on the tag matching but should do the job:
$pattern = '/<\w+>(.+)<\/\w+>/';
preg_match($pattern, $line, $matches);
returning the untagged data into $matches[1] and the tagged data into
$matches[0]
This assumes that you have only a single tagged entry per line.
Niel
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---