如何格式化RSS feed内容描述?

问题描述

| 我想格式化我的RSS Feed内容。喜欢在Description标签中嵌入一些信息。我正在创建wordpress RSS Feed并尝试创建RSS 2.0
<?xml version=\"1.0\"?>
<RSS version=\"2.0\">
<channel>
<item>
<title>firstquestion</title>
<url>test-domain.com</url>
<description>This is some ifnormation on the description. The below are the answers for the new question</description></item>
</channel>
</RSS>
现在,我想格式化或进一步格式化一些带有特殊字符的表或信息,甚至以tags1ѭ格式的html标签格式化……我该怎么做? 当我简单地插入时,它给我一个错误?     

解决方法

        您可以在description元素中包含HTML,但是必须使用htmlspecialchars对其进行编码。
$description = \'<strong>Strong formatting</strong> or <em>emphasis</em>.\';
$item = \'<item>
           <title>firstquestion</title>
           <url>test-domain.com</url>
           <description>\'.htmlspecialchars($description).\'</description>
         </item>\';
    ,        使用CDATA部分:
$description = \'<strong>Strong formatting</strong> or <em>emphasis</em>.\';
$item = \'<item>
           <title>firstquestion</title>
           <url>test-domain.com</url>
           <description><![CDATA[\'.$description.\']]></description>
         </item>\';