yortzec Posted January 29, 2010 Share Posted January 29, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/190297-why-wont-this-short-code-work-writing-to-rss-file/ Share on other sites More sharing options...
salathe Posted January 29, 2010 Share Posted January 29, 2010 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). Quote Link to comment https://forums.phpfreaks.com/topic/190297-why-wont-this-short-code-work-writing-to-rss-file/#findComment-1003950 Share on other sites More sharing options...
yortzec Posted January 29, 2010 Author Share Posted January 29, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/190297-why-wont-this-short-code-work-writing-to-rss-file/#findComment-1003979 Share on other sites More sharing options...
yortzec Posted January 29, 2010 Author Share Posted January 29, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/190297-why-wont-this-short-code-work-writing-to-rss-file/#findComment-1004013 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.