Jump to content

Why Won't This Short Code Work? Writing to RSS File...


Recommended Posts

Okay, I've been trying to write to an rss file that has permissions as 666. Here's the code: ($name, $comments, and $added are already defined) Thanks so much for helping! (Or trying to!)

 

$myFile = "rssfeed.rss";
$fh = fopen($myFile, 'r'); or die("can't open file");
$theData = fread($fh, filesize($myFile));

$shortstring = substr_replace($theData, "", -16, 16);
fwrite($fh, $shortstring);

$stringData = "
<item xmlns:atom=\"http://www.w3.org/2005/Atom\">
<title xmlns:atom=\"http://www.w3.org/2005/Atom\">$name</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\">$comments</description>
<pubDate xmlns:atom=\"http://www.w3.org/2005/Atom\">$added</pubDate>
</item> </channel></rss>";

fwrite($fh, $stringData);

$endData = '</channel></rss>"
fwrite($fh, $endData);

fclose($fh);

 

[attachment deleted by admin]

You only open the file for reading, not reading and writing (see the 2nd line of your code posted above). That's quite apart from your code being malformed (see where the syntax highlighting breaks in your post).

Alright..hmm.. thanks for that, but it still doesn't work....hm....here's my new code, tell me if you notice why it's not working:

 

$myFile = "rssfeed.rss";
$fh = fopen($myFile, 'r'); or die("can't open file");
$theData = fread($fh, filesize($myFile));
fclose($fh);

$shortstring = substr_replace($theData, "", -16, 16);

$stringData = "
<item xmlns:atom=\"http://www.w3.org/2005/Atom\">
<title xmlns:atom=\"http://www.w3.org/2005/Atom\">$name</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\">$comments</description>
<pubDate xmlns:atom=\"http://www.w3.org/2005/Atom\">$added</pubDate>
</item> </channel></rss>";

$endData = "</channel></rss>"

$fh = fopen($myFile, 'w');

fwrite($fh, $shortstring);
fwrite($fh, $stringData);

fwrite($fh, $endData);
fclose($fh);

Figured it out. For those who want it in the archives, here was my final code:

 

$myFile = "rssfeed.rss";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);

$shortstring = substr_replace($theData, "", -22, 22);

$stringData = "
<item xmlns:atom=\"http://www.w3.org/2005/Atom\">
<title xmlns:atom=\"http://www.w3.org/2005/Atom\">$name</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\">$comments</description>
<pubDate xmlns:atom=\"http://www.w3.org/2005/Atom\">$added</pubDate>
</item> </channel></rss>";

$endData = "</channel></rss>";

$fh = fopen($myFile, 'w');

fwrite($fh, $shortstring);
fwrite($fh, $stringData);

fwrite($fh, $endData);
fclose($fh);

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.