我正在嘗試獲取 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 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消