RSS Feed Breakage
Well it seems my RSS feed is still a bit on the broken side. I changed something in the script and now it is having troubles creating it properly.
I don’t know how many out there know the specification for RSS feeds (my feed follows RSS 2.0 Specification) and one thing that I am having troubles with is converting HTML entities to their proper characters so that the RSS validates. Pretty much the character that I have the most problem with is the ampersand (&). When you use things like or » and using PHP’s built in function of html_entity_decode() it has not been parsing them properly and then the xml fails and the feed does not want to work in the various readers.
The script I use is a custom one that reads the 10 most recent blog entries and writes them to an XML file according to the RSS 2.0 Specification. It’s actually pretty straight-forward in the way it works. I have a header and footer variable and then a body variable that loops while it pulls the appropriate records from MySQL.
Below is the code I use in my loop while I pull from MySQL and try to parse though it:
[code]
<?php
while($blog = mysql_fetch_array($query, MYSQL_ASSOC)) {
// Strip HTML tags and convert any special characters
$description = $blog['body'];
$description = html_entity_decode($description);
// Modify date to RFC 822 Specification
$pubDate = date("D, d M Y H:i:s T", strtotime($blog['date_entered']));
// encode URL with - so that it is URL friendly (for Mod_rewrite)
$url = str_replace(" ", "-", $blog['title']);
// Actual body of the feed. Gets looped though and created for each Blog Entry
$feed = "<item>\n
<title>{$blog['title']}</title>\n
<description>{$description}</description>\n
<link>http://www.tingram.ca/blog/{$url}</link>\n
<pubDate>{$pubDate}</pubDate>\n
<guid>http://www.tingram.ca/blog/{$url}</guid>\n
</item>\n\n";
// Write the current Blog Entry to the file
fwrite($file, $feed);
}
?>
[/code]
Now perhaps it might be an issue with FCKeditor since I use that to insert my blog entries, but I’ve noticed that FCKeditor will convert the various entities to their more universal standard which is fine, I want it to do that, but when I read it from the MySQL record, PHP is not doing its proper job on decoding it. Perhaps I am using the wrong function?
If anyone out there can look at the above code and tell me an easier or perhaps better way to go about it, I would appreciate it. Also my formatting does not seem to stay in my RSS feed and the HTML tags seem to be stripped, even though I don’t strip them when I import the data from the database. I would like to have nice looking RSS feeds and not some blog of text like they are now.





