rss php feed not working or validating

Please support our RSS, Web Services and SOAP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Feb 2009
Posts: 1
Reputation: rmcgrady is an unknown quantity at this point 
Solved Threads: 0
rmcgrady rmcgrady is offline Offline
Newbie Poster

rss php feed not working or validating

 
0
  #1
Feb 24th, 2009
Hi forum,

Trying to create an RSS feed for my blog (not using a blog host or blog software). Seems to me the best way for me to do it is to use PHP in the XML to draw the last X posts from my MySQL database. So first, I added a .htaccess file to the directory with the line
AddType application/x-httpd-php .xml
...to make the php work inside the xml file.

My rss.xml looks like:

RSS, Web Services and SOAP Syntax (Toggle Plain Text)
  1. <?php header('Content-type: text/xml'); ?>
  2. <rss version="2.0">
  3.  
  4. <?php
  5. (connection goes here)
  6. (recordset goes here)
  7. ?>
  8. <channel>
  9. <title>X</title>
  10. <description>I like the Internet</description>
  11. <link>http://www.x.com</link>
  12.  
  13. <?php
  14. mysql_select_db($aCon, $acCon);
  15. $top5q="SELECT blogIndex,title,content,DATE_FORMAT(date,'%a, %d %b %Y %T') AS rfcdate,tag1,tag2,tag3,tag4,tag5,tag6,tag7,tag8,tag9,tag10 FROM rhododendrites_blog ORDER BY date DESC LIMIT 10";
  16. $recentp = mysql_query($top5q,$acCon) or die(mysql_error());
  17. while($row=mysql_fetch_array($recentp))
  18. { ?>
  19. <item>
  20. <title><?php
  21. echo htmlentities(strip_tags($row['title'])); ?>
  22. </title>
  23. <description>
  24. <?php echo $row['content']; ?>
  25. </description>
  26. <link>http://www.x.com/blog/post.php?blogid=<?php echo $row['blogIndex']; ?></link>
  27. <pubDate><?php echo $row['rfcdate']; ?></pubDate>
  28. </item>
  29. <?php } ?>
  30.  
  31. </channel>
  32. </rss>

I changed my website, of course, to x.com and the names of a couple vars. I'm new at this stuff and don't know what I should be paranoid about Sorry.

So not only does it not show any records (other than the initial channel info) when I surf to the URL of the feed directly, but when I try to validate it, I get this:

Sorry
This feed does not validate.
line 89, column 42: pubDate must be an RFC-822 date-time:
<pubDate><?php echo $row['rfcdate']; ?></pubDate>

In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendations.
Feeds should not be served with the "application/x-httpd-php" media type

line 84, column 3: title should not be blank
</title>

line 90, column 2: item should contain a guid element
</item>

line 93, column 0: Missing atom:link with rel="self"
</channel>



Help? :/ Spent hours on this so far and can't figure it out.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 827
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 135
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: rss php feed not working or validating

 
0
  #2
Feb 28th, 2009
looks like it is not parsing the php. maybe it's best to separate the php and xml. personally i use smarty templates to build the rss.

my rss code looks like this:
  1. <?php
  2. require_once 'smarty/Smarty.class.php';
  3. $tpl = new Smarty();
  4. require_once './inc/defines.inc.php';
  5. $tpl->force_compile = false;
  6. $tpl->caching = 1;
  7. $tpl->cache_lifetime = 14400;
  8. if ($tpl->is_cached('rss.tpl')) {
  9. $content = $tpl->fetch('rss.tpl');
  10. }
  11. else {
  12. $content = '';
  13. $db_link = @mysql_connect(HOST, USER, PASS);
  14. @mysql_select_db(DB);
  15. $query = "<omitted>";
  16. $result = @mysql_query($query);
  17. if ($result) {
  18. $rss = array ();
  19. while ($row = mysql_fetch_assoc($result)) {
  20. $dp = explode('-', $row['date']);
  21. $dt = mktime(12, 0, 0, $dp[1], $dp[2], $dp[0]);
  22. $row['date'] = date("D, d M Y H:i:s ", $dt) . '+0100';
  23. $row['article'] = substr($row['article'], 0, strpos($row['article'], '</p>'));
  24. $row['article'] = htmlentities(strip_tags($row['article']));
  25. $rss[] = $row;
  26. }
  27. $pd = date("D, d M Y H:i:s ", time()) . '+0100';
  28. $tpl->assign('PUBDATE', $pd);
  29. $tpl->assign('YEAR', date('Y'));
  30. $tpl->assign('RSS', $rss);
  31. $content = $tpl->fetch('rss.tpl');
  32. }
  33. if ($db_link)
  34. mysql_close($db_link);
  35. }
  36. header("Content-Type: application/xml; charset=ISO-8859-1");
  37. echo $content;
  38. ?>

and my template like this:
RSS, Web Services and SOAP Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="ISO-8859-1" ?>
  2. <rss version="2.0">
  3. <channel>
  4. <title>Stichting Kledingbank Limburg - Actueel</title>
  5. <link>http://www.kledingbank-limburg.nl/page/actueel</link>
  6. <description>Actueel nieuws</description>
  7. <language>nl-nl</language>
  8. <lastBuildDate>{$PUBDATE}</lastBuildDate>
  9. <pubDate>{$PUBDATE}</pubDate>
  10. <copyright>Copyright 2005-{$YEAR} Stichting Kledingbank Limburg</copyright>
  11. <image>
  12. <url>http://www.kledingbank-limburg.nl/img/kledingbank-limburg.png</url>
  13. <link>http://www.kledingbank-limburg.nl/</link>
  14. </image>
  15. {foreach from=$RSS item=item}
  16. <item>
  17. <title>{$item.title}</title>
  18. <link>{$item.url}</link>
  19. <description>{$item.article}</description>
  20. <author>{$item.author}</author>
  21. <pubDate>{$item.date}</pubDate>
  22. <category>{$item.category}</category>
  23. </item>
  24. {/foreach}
  25. </channel>
  26. </rss>
Last edited by pritaeas; Feb 28th, 2009 at 8:04 am. Reason: readability
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 15
Reputation: barbz is an unknown quantity at this point 
Solved Threads: 0
barbz barbz is offline Offline
Newbie Poster

Re: rss php feed not working or validating

 
0
  #3
Apr 28th, 2009
you could use this.. its very simple..

RSS, Web Services and SOAP Syntax (Toggle Plain Text)
  1. <?php $db = new mysqli("localhost", "root", "", "rss"); ?>
  2. <?php header('Content-type: text/xml'); ?>
  3. <?php echo "<?";?>xml version="1.0" encoding="iso-8859-1"<?php echo "?> ";?>
  4. <rss version="2.0" xmlns:atom="http://www.geocities.com/jas_jo679">
  5. <channel>
  6. <title> Making a Dynamic RSS Feed</title>
  7. <description> Getting items from the database.</description>
  8. <link> http://barbz.0fees.net/</link>
  9. <copyright> Your Copyright Information</copyright>
  10. <atom:link href="http://barbz.0fees.net/" rel="self" type="application/rss+xml" />
  11. <image>
  12. <url> http://www.upd.edu.ph/~music/graphics/up%20logo%20colored.gif</url>
  13. </image>
  14.  
  15. <?php
  16. $query = "SELECT * FROM `article`";
  17. $results = $db-> query($query);
  18. $number = $results->num_rows;
  19.  
  20. for ($i = 1; $i <= $number; $i++) {
  21. $row = $results-> fetch_assoc();
  22. $title = $row['title'];
  23. $description = $row['body'];
  24. $link = $row['link'];
  25. ?>
  26. <item>
  27. <title> <?php echo $title; ?> </title>
  28. <description> <?php echo $description; ?> </description>
  29. <link> <?php echo $link; ?> </link>
  30. </item>
  31. <?php
  32. }?>
  33. </channel>
  34. </rss>
  35. <?php
  36.  
  37. $db-> close();
  38.  
  39. ?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the RSS, Web Services and SOAP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC