| | |
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
![]() |
•
•
Join Date: Feb 2009
Posts: 1
Reputation:
Solved Threads: 0
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
...to make the php work inside the xml file.
My rss.xml looks like:
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.
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)
<?php header('Content-type: text/xml'); ?> <rss version="2.0"> <?php (connection goes here) (recordset goes here) ?> <channel> <title>X</title> <description>I like the Internet</description> <link>http://www.x.com</link> <?php mysql_select_db($aCon, $acCon); $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"; $recentp = mysql_query($top5q,$acCon) or die(mysql_error()); while($row=mysql_fetch_array($recentp)) { ?> <item> <title><?php echo htmlentities(strip_tags($row['title'])); ?> </title> <description> <?php echo $row['content']; ?> </description> <link>http://www.x.com/blog/post.php?blogid=<?php echo $row['blogIndex']; ?></link> <pubDate><?php echo $row['rfcdate']; ?></pubDate> </item> <?php } ?> </channel> </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.
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:
and my template like this:
my rss code looks like this:
php Syntax (Toggle Plain Text)
<?php require_once 'smarty/Smarty.class.php'; $tpl = new Smarty(); require_once './inc/defines.inc.php'; $tpl->force_compile = false; $tpl->caching = 1; $tpl->cache_lifetime = 14400; if ($tpl->is_cached('rss.tpl')) { $content = $tpl->fetch('rss.tpl'); } else { $content = ''; $db_link = @mysql_connect(HOST, USER, PASS); @mysql_select_db(DB); $query = "<omitted>"; $result = @mysql_query($query); if ($result) { $rss = array (); while ($row = mysql_fetch_assoc($result)) { $dp = explode('-', $row['date']); $dt = mktime(12, 0, 0, $dp[1], $dp[2], $dp[0]); $row['date'] = date("D, d M Y H:i:s ", $dt) . '+0100'; $row['article'] = substr($row['article'], 0, strpos($row['article'], '</p>')); $row['article'] = htmlentities(strip_tags($row['article'])); $rss[] = $row; } $pd = date("D, d M Y H:i:s ", time()) . '+0100'; $tpl->assign('PUBDATE', $pd); $tpl->assign('YEAR', date('Y')); $tpl->assign('RSS', $rss); $content = $tpl->fetch('rss.tpl'); } if ($db_link) mysql_close($db_link); } header("Content-Type: application/xml; charset=ISO-8859-1"); echo $content; ?>
and my template like this:
RSS, Web Services and SOAP Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="ISO-8859-1" ?> <rss version="2.0"> <channel> <title>Stichting Kledingbank Limburg - Actueel</title> <link>http://www.kledingbank-limburg.nl/page/actueel</link> <description>Actueel nieuws</description> <language>nl-nl</language> <lastBuildDate>{$PUBDATE}</lastBuildDate> <pubDate>{$PUBDATE}</pubDate> <copyright>Copyright 2005-{$YEAR} Stichting Kledingbank Limburg</copyright> <image> <url>http://www.kledingbank-limburg.nl/img/kledingbank-limburg.png</url> <link>http://www.kledingbank-limburg.nl/</link> </image> {foreach from=$RSS item=item} <item> <title>{$item.title}</title> <link>{$item.url}</link> <description>{$item.article}</description> <author>{$item.author}</author> <pubDate>{$item.date}</pubDate> <category>{$item.category}</category> </item> {/foreach} </channel> </rss>
Last edited by pritaeas; Feb 28th, 2009 at 8:04 am. Reason: readability
"If it is NOT source, it is NOT software."
-- NASA
-- NASA
•
•
Join Date: Jan 2009
Posts: 15
Reputation:
Solved Threads: 0
you could use this.. its very simple..
RSS, Web Services and SOAP Syntax (Toggle Plain Text)
<?php $db = new mysqli("localhost", "root", "", "rss"); ?> <?php header('Content-type: text/xml'); ?> <?php echo "<?";?>xml version="1.0" encoding="iso-8859-1"<?php echo "?> ";?> <rss version="2.0" xmlns:atom="http://www.geocities.com/jas_jo679"> <channel> <title> Making a Dynamic RSS Feed</title> <description> Getting items from the database.</description> <link> http://barbz.0fees.net/</link> <copyright> Your Copyright Information</copyright> <atom:link href="http://barbz.0fees.net/" rel="self" type="application/rss+xml" /> <image> <url> http://www.upd.edu.ph/~music/graphics/up%20logo%20colored.gif</url> </image> <?php $query = "SELECT * FROM `article`"; $results = $db-> query($query); $number = $results->num_rows; for ($i = 1; $i <= $number; $i++) { $row = $results-> fetch_assoc(); $title = $row['title']; $description = $row['body']; $link = $row['link']; ?> <item> <title> <?php echo $title; ?> </title> <description> <?php echo $description; ?> </description> <link> <?php echo $link; ?> </link> </item> <?php }?> </channel> </rss> <?php $db-> close(); ?>
![]() |
Other Threads in the RSS, Web Services and SOAP Forum
- Previous Thread: RSS feed problem
- Next Thread: pls check my rss reader..^^
| Thread Tools | Search this Thread |
.htaccess 301 accept access alltop api authentication binarysecuritytoken blog card collaboration credit data development ebay email evernote flash google government highrise htaccess intel internet legal live netbeans patent paypal php podcast proxy redirect rss rssfeeds searchmonkey server service soap software swappingxmlfromflash swappingxmlnodes url web webservices webservicesecurity wiki wikipedia xerces xml xslt y!os yahoo ydn





