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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.