[thelist] placing the pointer in a text file using PHP..

Tom Dell'Aringa pixelmech at yahoo.com
Mon Dec 30 16:51:01 CST 2002


--- Carl J Meyer <cjmeyer at npcc.net> wrote:
> Tom,
>
> You've got the idea.  I haven't done lots of XML parsing in PHP,
> but it
> looks to me like the easiest route would be to use a flag variable
> for
> parsing the xml and only set it to true once you've found <?xml:
>
> (this all replaces your single while statement)
> -----------------
> $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).

I definitely appreciate the help so far, I'm surprised this didn't
work! Any other directions to point me in? (or anyone else?)

Tom

=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



More information about the thelist mailing list