我正在嘗試獲取 RSS 提要,更改一些文本,然后將其作為 RSS 提要再次提供。但是,我編寫的代碼沒(méi)有正確驗(yàn)證。我收到這些錯(cuò)誤:第 3 行,第 0 列:缺少 rss 屬性:版本第 14 行,第 6 列:未定義的項(xiàng)目元素:內(nèi)容(出現(xiàn) 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貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個(gè)贊
第一個(gè)錯(cuò)誤只是缺少一個(gè)屬性,很簡(jiǎn)單:
<rss version="2.0" ...>
對(duì)于<p>
和其他 HTML 元素,您需要對(duì)它們進(jìn)行轉(zhuǎn)義。該文件應(yīng)如下所示:
<p>...
還有其他方法,但這是最簡(jiǎn)單的方法。在 PHP 中,您可以調(diào)用一個(gè)函數(shù)來(lái)對(duì)實(shí)體進(jìn)行編碼。
$output .= htmlspecialchars(" <p>Paragraph</p> ");
至于<content>
標(biāo)簽問(wèn)題,應(yīng)該是<description>
。該<content>
標(biāo)簽當(dāng)前生成兩個(gè)錯(cuò)誤。<description>
在兩個(gè)地方都將其更改為應(yīng)該可以解決兩個(gè)錯(cuò)誤。
否則,您似乎了解基礎(chǔ)知識(shí)。你<open>
和</close>
標(biāo)簽和那些必須匹配。您還可以使用所謂的空標(biāo)簽:<empty/>
它們獨(dú)立存在,但不包含內(nèi)容且沒(méi)有結(jié)束標(biāo)簽。
- 2 回答
- 0 關(guān)注
- 137 瀏覽
添加回答
舉報(bào)
0/150
提交
取消