我正在嘗試使用下面的代碼在我的網站上生成RSS訂閱源。該RSS是出現,但我有兩個問題:Rss Feed,生成圖片
當進料顯示我的網頁上的圖片顯示不出來,您看到的IMG鏈接直接出現這樣的頁面上...
<a href="http://movies.nytimes.com/2011/11/18/movies/garbo-the-spy-about-juan-pujol-garcia-review.html?partner=rssnyt&emc=rss"><img src="http://graphics8.nytimes.com/images/2011/11/18/movies/18RDP_GARBO/18RDP_GARBO-thumbStandard.jpg" border="0" height="75" width="75" hspace="4" align="left"></a>
如何限制我網站上顯示的文章數量?
這裏是鏈接到RSS:Spy RSS FEED 這裏是我使用的代碼:
<?php
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
$locations = array('http://topics.nytimes.com/topics/reference/timestopics/subjects/e/espionage/index.html?rss=1');
srand((float) microtime() * 10000000); // seed the random gen
$random_key = array_rand($locations);
function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
$tag = $name;
} elseif ($name == "ITEM") {
$insideitem = true;
}
}
function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link;
if ($name == "ITEM") {
printf("<dt><b><a href='%s' target=new>%s</a></b></dt>",
trim($link),htmlspecialchars(trim($title)));
printf("<dt>%s</dt><br><br>",htmlspecialchars(trim($description)));
$title = "";
$description = "";
$link = "";
$insideitem = false;
}
}
function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
$link .= $data;
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen($locations[$random_key], 'r')
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);
?>
你自己寫了那個代碼嗎? – Tomalak