RE: [PHP] logging data to xml
| From: | Jay Blanchard | Date: | Fri, 15 Aug 2003 11:49:13 +0000 |
| Subject: | RE: [PHP] logging data to xml | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-159675@lists.php.net to get a copy of this message | ||
[snip]
I have been trying to log some data to an xml file. Whta my problem is
now
is that the </root> tag needs to be either replaced (overwritten) or i
need to
get the data in before EOF-1. I have spend some time on the manual, but
could not find out hoe exactly i should get the last row and then move
one up
again to log the stuff to the file.
[/snip]
A couple of things occured to me, but I am not sure that they're
desirable...
With </root> being the last tag (does it occupy its own line?) you could
(pseudo-code, not tested and certain to be incomplete)...
while(!feof($theXMLLogFile)){
$theXMLLine = fgets($theXMLLogFile, 255);
if($theXMLLine == "</root>"){
$theNewLogLine = "stuff you need to write \n </root>";
ereg_replace("</root>", "$theNewLogLine",
$theXMLLogFile);
}
}
Now, makes you read the file all the way through each time, but you
could open the file for appending, (fopen with a+) which places the file
pointer at the EOL. You can test this last line pointer to make sure it
is </root> and do the replace...
HTH!