Getting the file pointer at the end of a file
Posted: Tue Jun 14, 2005 11:40 am
Hi all, again for a tremendously stupid question probably
but I've searched the web for a while already, not finding what I need... Thus I come to you for aid 
My problem: I was already successful in an attempt to parse an XML file (just parsing, no DTD). Now I want to add some information to this XML file. I tried to do this using the standard file tools: fopen, fseek, fwrite.
I wanted to edit the following file:
To add a new entry, a new "topic" to be exact, I would want to remove the last line
and replace it by some new tags.
So i did the following:
Output gives me:
Meaning the seek was NOT done...
I have tried nearly anything to make this work...
Also note that seek won't work when in Append mode ("a" and "a+"), as stated on php.net (http://uk2.php.net/fseek):
Thanks in advance!
My problem: I was already successful in an attempt to parse an XML file (just parsing, no DTD). Now I want to add some information to this XML file. I tried to do this using the standard file tools: fopen, fseek, fwrite.
I wanted to edit the following file:
Code: Select all
<?xml version="e;1.0"e; encoding="e;ISO-8859-1"e;?>
<news>
<topic>
<title>XML Parser works!</title>
<date>14-06-2005</date>
<body>Body text</body>
</topic>
</news>Code: Select all
</news>So i did the following:
Code: Select all
$news_xml = fopen("e;news.xml"e;,"e;w+"e;);
echo fseek($news_xml,-6,SEEK_END);Code: Select all
-1I have tried nearly anything to make this work...
Also note that seek won't work when in Append mode ("a" and "a+"), as stated on php.net (http://uk2.php.net/fseek):
Any ideas? Or is there some kind of "smart" way of adding data to an XML file?Note: If you have opened the file in append ("a" or "a+") mode, any data you write to the file will always be appended, regardless of the file position.
Thanks in advance!