Jump to content

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


yortzec

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);

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.