A few fixes for your RSS feed
Thanks to faithful readers Louis and Daniel, I fixed my feed, which wasn’t recognized by certain RSS aggregators. I also apologize for inconvenience to all of you who had such problems. My FeedDemon will digest anything, so I had no clue something’s wrong. Anyway, shame on me.
Incorrect header syntax
The problem was in incorrectly labeled header Last Modified, which is correctly spelled Last-Modified (with dash). In case you missed that lesson, a HTTP header field name can not contain spaces. For example, the Content-Type is correct, the Content Type is incorrect. Also from the HTTP specs:
“Any header fields which are not understood should be ignored.”
CDATA—what it’s good for?
Some blog management systems output feeds with a post content within legible opening <content:encoded> and closing </content:encoded> tags. This way the original HTML structure (with its’ elements like headings or paragraphs) can be preserved and viewed in your favorite RSS reader. Since XML syntax is very strict, one must also escape those tags by placing <![CDATA[ before and ]]> after the content, so XML processor knows those tags are not part of the XML structure.
“CDATA sections MAY occur anywhere character data may occur; they are used to escape blocks of text containing characters which would otherwise be recognized as markup. CDATA sections begin with the string
<![CDATA[and end with the string]]>”
Absolute vs. relative paths
If you run your feed through Feed Validator, it might throw you an error regarding relative paths to your images or files. This can be fixed by simple preg_replace() snippet, for example:
<?php
echo '<content:encoded><![CDATA[';
echo preg_replace('/<(img src|a href)="\//si', '<$1="http://' . $_SERVER['HTTP_HOST'] . '/', $content);
echo ']]></content:encoded>';
?>
The above ensures that every <img src="/image.jpg" /> is replaced with <img src="http://yoursite.com/image.jpg" /> and also <a href="/file.zip" /> is replaced with <a href="http://yoursite.com/file.zip" />. If you use different paths, for example ../../image.jpg, the above will not work (actually it might break everything), but you’ve got starting point to tweak it to your needs. Read more about preg_replace() in PHP manual.

7 Comments
I’m on the verge of unsubscribing, because when I click through onto articles like this:
http://www.maratz.com/blog/archives/2005/06/28/funny-teasers/
I don’t get any of the example images or anything - which is quite important to the article, wouldn’t you say? No, I’m not switching Referer on. You don’t need it.
Comment (#) by Jim — 30th June 2005.
And that is your choice with which I’m perfectly okay : )
Comment (#) by marko — 30th June 2005.
Don’t get me wrong, I’m not telling you to or threatening to leave :). But it’s an unnecessary annoyance and if it unnecessarily annoys me again, I’ll just give up and unsubscribe. And that’s my choice, and I’m sure you are perfectly okay with that too :).
Comment (#) by Jim — 30th June 2005.
Wow, that was fast! I just emailed you this morning and not only a site fix but a write-up as well? I hope you have more bugs in this site . . .
Comment (#) by Dan Mall — 30th June 2005.
Dan, it’s never a question of not being able to handle things, but it’s often lack of extra few hours to seat down and fix the bug. Anyway, thanks again to you and Louis for reporting those issues.
Comment (#) by marko — 30th June 2005.
I’m puzzled by the use of ‘content’ namespace specified for RSS version 1.0 and not listed ‘compatible’ with RSS 2.0.
Does declaring the namespace still help aggregators even in RSS 2.0? That shouldn’t be, since 1.0 isn’t valid 2.0 (but 0.91 and 0.92 are).
Comment (#) by Mislav — 3rd July 2005.
I was wondering about this, thanks for the information.
Comment (#) by System — 19th April 2006.
Sorry, the comment form is closed at this time, but if you have anything to say, please send me a message.