我想问一下,我看到这个帖子的脚本。
脚本仍然正常工作,但我希望在我的网站上包含许多Feed并提交,我该如何解决?
example:
web1.domain.com/feed
web2.domain.com/feed
web3.domain.com/feed
...
我想将Feed子域显示到我的顶级域名。
$rss = new DOMDocument();
$rss->load('http://web.domain.com/feed/');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$htmlStr = $node->getElementsByTagName('description')->item(0)->nodeValue;
$html = new DOMDocument();
$html->loadHTML($htmlStr);
//get the first image tag from the description HTML
$imgTag = $html->getElementsByTagName('img');
$img = ($imgTag->length==0)?'noimg.png':$imgTag->item(0)->getAttribute('src');
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'category' => $node->getElementsByTagName('category')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'image' => $img,
);
array_push($feed, $item);
}
$limit = 2;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$img = $feed[$x]['image'];
$category = str_replace(' & ', ' & ', $feed[$x]['category']);
$date = date('j F Y G:i', strtotime($feed[$x]['date']));
echo '<li>';
echo '<a href="'.$link.'" title="'.$title.'">';
echo '<div class="blog-widget-img left relative">';
echo '<img src="'.$img.'" height="100" width="165">';
echo '</div>';
echo '<div class="blog-widget-text left relative">';
echo '<span class="side-list-cat">'.$category.'</span>';
echo '<h2>'.$title.'</h2>';
echo '<span><time>'.$date.'</time></span>';
echo '</div>';
echo '</a>';
echo '</li>';
}
更新:
我找到了解决方案检查并且可以正常工作
$my_feeds = array('http://web1.domain.com/feed',
'http://web2.domain.com/feed',
'http://web3.domain.com/feed');
foreach ($my_feeds as $my_feed)
{
$rss = new DOMDocument();
$rss->load ($my_feed); //load more feed with variable
$feed = array();
//star feed here
}