Jump to content

Recommended Posts

I need some help here. I am trying to use php to write to an rss file (Basically a Unicode-8 text file with extension ".rss") when a person writes a post on my website. I used a php script that I downloaded to set up several things for me, so I already have all the variables i will need. They are: $name, $comments, and $added, representing the title of an rss article, the article itself, and the date the article was written, respectively. I also know where to put the function to write to the file. (But I don't know what to put in it) I want to make the function not replace everything in the rss file i am writing to. There will have to be more text above where I want to write in the rss file, and a static number of characters below it. (To be exact, the text I want to put in must be 16 characters before the end of the document, but I can always add more returns as "buffer" characters, to be sure that the code won't be placed in the wrong place) I also will need to put certain text in between the characters, and you will get the idea in the code below.

 

This is what I want to be written in the file:

 

--Here will be lots of text giving information about the rss feed, which I will never need to change. (I found it unnecessary to post them here)

--Earlier articles might be here

<item xmlns:atom="http://www.w3.org/2005/Atom">
<title xmlns:atom="http://www.w3.org/2005/Atom">[b]$name[/b]</title>
<link xmlns:atom="http://www.w3.org/2005/Atom"> http://simh.host56.com/simh/gbook/gbook.php</link>
<guid xmlns:atom="http://www.w3.org/2005/Atom"> http://simh.host56.com/simh/gbook/gbook.php</guid>
<description xmlns:atom="http://www.w3.org/2005/Atom">[b]$comments[/b]</description>
<pubDate xmlns:atom="http://www.w3.org/2005/Atom">[b]$added[/b]</pubDate>
</item>

</channel>
</rss>

 

 

I hope you understand what I mean. Please ask if you need more information. Thanks so much for the help!

 

P.S. The "</channel></rss>" at the end of the code are the static 16 characters I was talking about.

Link to comment
https://forums.phpfreaks.com/topic/189666-help-writing-to-file-with-delimeters/
Share on other sites

<?php
//convert post vars

$write_this="
<item xmlns:atom=\"http://www.w3.org/2005/Atom\">
<title xmlns:atom=\"http://www.w3.org/2005/Atom\">[b]$name[/b]</title>
<link xmlns:atom=\"http://www.w3.org/2005/Atom\"> http://simh.host56.com/simh/gbook/gbook.php</link>
<guid xmlns:atom=\"http://www.w3.org/2005/Atom\"> http://simh.host56.com/simh/gbook/gbook.php</guid>
<description xmlns:atom=\"http://www.w3.org/2005/Atom\">[b]$comments[/b]</description>
<pubDate xmlns:atom=\"http://www.w3.org/2005/Atom\">[b]$added[/b]</pubDate>
</item> </channel></rss>';

file_put_contents($file.rss","$write_this");
?>

 

 

:) That will be $10.00 to any Haiti disaster fund. :)

:( If you dont donate karma will force your hair to grow down, wrap around your eyeballs and blind you!  :(

 

 

HTH

Teamatomic

 

 

edited for screwed code

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.