[thelist] placing the pointer in a text file using PHP..
Carl J Meyer
cjmeyer at npcc.net
Mon Dec 30 17:11:01 CST 2002
Tom,
Hrm. Should have tested that code - not sure what's going on exactly
and don't have time to dig into it. Looks like the preg_replace isn't
doing its job for some reason, maybe my regex is broke somehow, or maybe
the preg_ functions don't like strings containing newlines. Anyhow, the
following code is faster and cleaner, and actually does work:
$parsing = false;
while ($data = fread($fp, 4096))
{
if($data = strstr($data, '<?xml'))
$parsing = true;
if(!$parsing) continue;
print $data;
}
Give that a try,
Carl
On Mon, 2002-12-30 at 14:50, Tom Dell'Aringa wrote:
> > -----------------
> > $parsing = false;
> > while ($data = fread($fp, 4096))
> > {
> > if(preg_match('/<\?xml/', $data))
> > {
> > $data = preg_replace('/^.*<\?xml/', '<?xml', $data);
> > $parsing = true;
> > }
> > if(!$parsing) continue;
> > xml_parse($xml_parser, $data, feof($fp))
> > or die(sprintf("XML error: %s at line %d",
> > xml_error_string(xml_get_error_code($xml_parser)),
> > xml_get_current_line_number($xml_parser)));
> > }
> > ------------------
>
> Hmm..this all makes perfect sense while reading the code, and yet I
> still get the same error. I'm guessing that preg_match('/<\?xml/',
> $data) found the string, and the preg_replace() was to remove
> everything before it?
> I think the problem is, it never actually removed the header text.
> When I hit the xml_parse, it stills parses ALL of $data. (otherwise I
> wouldn't get the error).
>
> I tried to test this theory by commenting out the preg_replace, but
> nothing changed and viewing the data with view source looks the
> same... note I did change my fopen() parameter to 'r+' so it is open
> to read and write (and the permissions are set to 777).
More information about the thelist
mailing list