The RSS Advisory Board page sums up the problem fairly nicely:
The specification has lacked clarity regarding whether HTML is
permitted in elements other than an item's description, leading to
wide variance in how aggregators treat character data in other
elements. This makes it especially difficult for a publisher to
determine how to encode the characters "&" and "<", which must be
encoded in XML.
Which is to say, there isn't a 'right' way. In theory, you should be able to get away with not using the CDATA tags, and then HTML encoding your title. For example, this works for me in Firefox & IE8:
$title = 'August 1st: MFU President & friends on farm bill';
echo '<title>'.trim($title).'</title>';
However the W3 RSS validator (is this what you are using?) recommends against it because of the &
, based on the page linked above. They suggest using the hexadecimal character reference, but only for &
and <
. The easiest way to implement this is probably a simple str_replace
:
$title = 'August 1st: MFU President & friends on farm bill';
$title = str_replace(array('&', '<'), array('&', '<'), $title);
echo '<title>'.trim($title).'</title>';
(note I've made the starting string a bare &
)
I feel compelled to mention this blog post as well, which demonstrates that there isn't really a way to make all readers happy all of the time. But the last method should get most of them.