Jump to content

Help - Writing to File with Delimeters


yortzec

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

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.