我正在尝试获取 RSS 提要,更改一些文本,然后将其作为 RSS 提要再次提供。但是,我编写的代码没有正确验证。我收到这些错误:第 3 行,第 0 列:缺少 rss 属性:版本第 14 行,第 6 列:未定义的项目元素:内容(出现 10 次)这是我的代码:<?phpheader("Content-type: text/xml");echo "<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet type='text/xsl'?><?xml-stylesheet type='text/xsl' media='screen' href='/~d/styles/rss2full.xsl'?><rss xmlns:content='http://purl.org/rss/1.0/modules/content/'><channel><title>Blaakdeer</title><description>Blog RSS</description><language>en-us</language>";$html = "";$url = "http://feeds.feedburner.com/vga4a/mPSm";$xml = simplexml_load_file($url);for ($i = 0; $i < 10; $i++){$title = $xml->channel->item[$i]->title;$description = $xml->channel->item[$i]->description;$content = $xml->channel->item[$i]->children("content", true);$content = preg_replace("/The post.*/","", $content);echo "<item><title>$title</title><description>$description</description><content>$content</content></item>"; }echo "</channel></rss>";
2 回答
临摹微笑
TA贡献1982条经验 获得超2个赞
第一个错误只是缺少一个属性,很简单:
<rss version="2.0" ...>
对于<p>
和其他 HTML 元素,您需要对它们进行转义。该文件应如下所示:
<p>...
还有其他方法,但这是最简单的方法。在 PHP 中,您可以调用一个函数来对实体进行编码。
$output .= htmlspecialchars(" <p>Paragraph</p> ");
至于<content>
标签问题,应该是<description>
。该<content>
标签当前生成两个错误。<description>
在两个地方都将其更改为应该可以解决两个错误。
否则,您似乎了解基础知识。你<open>
和</close>
标签和那些必须匹配。您还可以使用所谓的空标签:<empty/>
它们独立存在,但不包含内容且没有结束标签。
- 2 回答
- 0 关注
- 126 浏览
添加回答
举报
0/150
提交
取消