...

View Full Version : Replace last line in file



lykoulos
09-07-2009, 06:23 AM
Hello, I have a PHP file which writes items on an rss.xml file.

The XML file ends in
</channel></rss>
This is the last line.

The thing is, that every time the PHP writes a new item on the XML file, it must delete the last line of the XML file first. How can I do this? This is my code, please help.


<?php
header ("Location: http://www.google.com");

$handlexml = fopen("rss.xml", "a");
$time = date("h:i:s",time() + 7200);
$imerom = date("j-m-Y");
$data = "rss.xml";

fwrite($handlexml, "<item>");
fwrite($handlexml, "\r\n");
fwrite($handlexml, "<title>");
fwrite($handlexml, "$imerom");
fwrite($handlexml, " ");
fwrite($handlexml, "$date");
fwrite($handlexml, "</title>");
fwrite($handlexml, "\r\n");
fwrite($handlexml, "<link>http://www.google.com");
fwrite($handlexml, "</link>");
fwrite($handlexml, "\r\n");
fwrite($handlexml, "<guid>http://www.google.com");
fwrite($handlexml, "</guid>");
fwrite($handlexml, "\r\n");
fwrite($handlexml, "<pubDate>Mon, 10 Sep 2009 18:37:00 GMT</pubDate>");
fwrite($handlexml, "\r\n");
fwrite($handlexml, "<description>decriptio</description>");
fwrite($handlexml, "\r\n");
fwrite($handlexml, "</item>");
fwrite($handlexml, "\r\n");
fwrite($handlexml, "\r\n");
fwrite($handlexml, "</channel></rss>");

fclose($handlexml);
exit;
?>

abduraooft
09-07-2009, 07:37 AM
Why are you using fwrite() to write into an xml file? There's simpleXML (http://php.net/manual/en/intro.simplexml.php) and DOMDocument (http://php.net/manual/en/class.domdocument.php)to manipulate xml files in php

lykoulos
09-07-2009, 07:48 AM
Why are you using fwrite() to write into an xml file? There's simpleXML (http://php.net/manual/en/intro.simplexml.php) and DOMDocument (http://php.net/manual/en/class.domdocument.php)to manipulate xml files in php

I don't have that kind of knowledge, i saw the links you gave me and i didn't understand a thing. I was just looking for a "find and replace" tag, just to erase the last line of the xml file.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum