Dynamic RSS feed woes
PHP can be tricky
When you want something to be bleading edge, you’ll occasionally get cut. My RSS feed for Can’t Count Sheep is dynamically generated. At the moment, this is being accomplished with a PHP script that graps the lastest six entries (based on file creation time) and builds an XML file out of them.
That seems to work all fine and dandy, except for the fact that PHP inserts a newline and return character (\n\r
) at the begining of every page it generates. HTML still validates, since it’s forgiving of that sort of thing. But the anal retentive RSS specs mean my feed doesn’t.
Embrace Postel’s Law
Postel’s Law, states that you should “be conservative in what you do, and liberal in what you accept from others”. It’s a principle Mark Pilgrim kept in mind when he designed his feed parser. Let’s hope that other news readers have done the same.
So, if you can (or can’t) read my RSS feed, leave a comment that lets me know what news reader you’re using. I’d like to know whether or not this bug is actually affecting anyone, so I can determine if it’s worth my time to hunt down a solution.
Problem solved
Well, thanks to a bit of PHP trickery, my problem’s been solvoed. I added the line echo '<?xml version="1.0">';
to the top of the file that controls display stuff and it works. All my HTML code validates as XHTML 1.0 Strict, and my RSS feed validates as RSS 2.0. Can’t Count Sheep works in PulpFiction and NewsFire, so I’m happy. Still working on some metadata stuff with regards to created vs. modified dates, but those bugs should be squashed shortly.