Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Replace last line in file

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

    The XML file ends in
    Code:
    </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 Code:
    <?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;
    ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Why are you using fwrite() to write into an xml file? There's simpleXML and DOMDocument to manipulate xml files in php
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Why are you using fwrite() to write into an xml file? There's simpleXML and DOMDocument 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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •