Jump to content

Replace last line in file


lykoulos

Recommended Posts

Hello, I have a PHP file which writes items on an rss.xml file.

 

The XML file ends in

 

</rss>

 

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, "</rss>");

fclose($handlexml);
exit;
?> 

Link to comment
https://forums.phpfreaks.com/topic/173451-replace-last-line-in-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.