LiamH Posted July 8, 2009 Share Posted July 8, 2009 Hi all. I've been trying to create some code for dynamic RSS, but failing miserably with it. When I go to validate it, there's always problems. But changing them doesn't seem to get me anywhere. I'll be honest, I don't really know what I'm doing and have been trying to follow several tutorials and getting errors in them all. This is the code I'm using; <?php header('Content-Type: text/xml'); echo '<?xml version="1.0" encoding="ISO-8859-1"?> <rss version="2.0"> <channel> <title>Gamedot.</title> <description>The latest news, reviews and features for all consoles, the PC and handhelds.</description> <link>http://www.gamedot.co.uk</link>'; $get_articles = "SELECT ArticleID, Headline, ArticlePreview, DATE_FORMAT(Date,'%a, %e %b %Y %T') as formatted_date FROM tblArticles ORDER BY Date DESC LIMIT 2"; $articles = mysql_query($get_articles) or die(mysql_error()); while ($article = mysql_fetch_array($articles)){ echo ' <item> <title>'.$article[Headline].'</title> <description><![CDATA[ '.$article[Preview].' ]]></description> <link>http://www.gamedot.co.uk/article.php?ArticleID='.$article[ArticleID]</link> <pubDate>'.$row[formatted_date].' GMT</pubDate> </item>'; } echo '</channel> </rss>'; ?> Has anyone got any experience in creating a dynamic RSS that could help? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/ Share on other sites More sharing options...
Philip Posted July 8, 2009 Share Posted July 8, 2009 What errors are you getting? Also try this (some of your quotes were off): <?php header('Content-Type: text/xml'); echo '<?xml version="1.0" encoding="ISO-8859-1"?> <rss version="2.0"> <channel> <title>Gamedot.</title> <description>The latest news, reviews and features for all consoles, the PC and handhelds.</description> <link>http://www.gamedot.co.uk</link>'; $get_articles = "SELECT ArticleID, Headline, ArticlePreview, DATE_FORMAT(Date,'%a, %e %b %Y %T') as formatted_date FROM tblArticles ORDER BY Date DESC LIMIT 2"; $articles = mysql_query($get_articles) or die(mysql_error()); while ($article = mysql_fetch_array($articles)){ echo ' <item> <title>'.$article['Headline'].'</title> <description><![CDATA[ '.$article['Preview'].' ]]></description> <link>http://www.gamedot.co.uk/article.php?ArticleID='.$article['ArticleID'].'</link> <pubDate>'.$row['formatted_date'].' GMT</pubDate> </item>'; } echo '</channel> </rss>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/#findComment-870927 Share on other sites More sharing options...
LiamH Posted July 8, 2009 Author Share Posted July 8, 2009 I just tried your code and got the following. It's easier if I send you to the validator. http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.gamedot.co.uk%2Frss.xml Quote Link to comment https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/#findComment-870943 Share on other sites More sharing options...
Philip Posted July 8, 2009 Share Posted July 8, 2009 Your extension shouldn't be .xml, it should be .php Quote Link to comment https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/#findComment-870944 Share on other sites More sharing options...
LiamH Posted July 8, 2009 Author Share Posted July 8, 2009 OK, thanks for the help so far. Seem to be getting somewhere now thanks to you guys. I've updated it, the link is now http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.gamedot.co.uk%2Frss.php The main error I'm getting now is pubDate must be an RFC-822 date-time: GMT Not sure what that means ??? Quote Link to comment https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/#findComment-870955 Share on other sites More sharing options...
defeated Posted July 8, 2009 Share Posted July 8, 2009 Once you get it to run as a php file then you can use mod rewrite as follows: RewritRule ^rss.xml rss.php in your .htaccess file. That way anybody can write rss.xml and it will open your xml.php file but look like it is opening rss.xml(which won't actually exist). Do get it running as rss.php first though. Quote Link to comment https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/#findComment-870962 Share on other sites More sharing options...
LiamH Posted July 8, 2009 Author Share Posted July 8, 2009 I have it kind of working now. Removed the date field to make it valid RSS. But only the view article link is displaying in the feed. Will have a play, see what I can find Quote Link to comment https://forums.phpfreaks.com/topic/165173-solved-dynamic-rss/#findComment-870964 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.