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
<?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.