0

我想在我的网站上显示两个或更多博客的帖子现在正在使用magpierss-0.72来获取帖子,我的代码是

require_once('rss_fetch.inc');
    $url = 'http://rajs-creativeguys.blogspot.com/feeds/posts/default?alt=rss'
    /*'http://raghuks.wordpress.com/feed/'*/;
    $rss = fetch_rss($url);
    foreach ($rss->items as $i => $item ) { 
        $title = strtoupper ($item['title']);
        $url   = $item['link'];
        $date = substr($item['pubdate'],0,26);
        //code to fetch only some text
        $desc = '';
        $max = 30;
        $arr = explode(' ', strip_tags($item['description']));
        $l = count($arr);
        if($l < $max) $max = $l;
        for($j=0;$j<$max;++$j) {
            $desc .= $arr[$j] . ' ';
        }
        $desc .= '.....';
        echo "<div class=\"blog\"><a target=\"_blank\" href=$url><h1>$title</h1>$desc<br/><br/>DATED : $date <br/><br/></a></div> ";
        if($i == 3) break; 
    }

在这里我只能指定一个提要的 url 并且可以获取但现在我想显示两个或更多博客的帖子请给我解决方案

提前致谢

4

1 回答 1

1

只需使用一个数组并放入另一个 foreach:

<?php
require_once('rss_fetch.inc');

$urls = array(
'http://rajs-creativeguys.blogspot.com/feeds/posts/default?alt=rss',
' more urls ... ',
);

foreach($urls as $url) {
    /*'http://raghuks.wordpress.com/feed/'*/;
    $rss = fetch_rss($url);
    foreach ($rss->items as $i => $item ) { 
        $title = strtoupper ($item['title']);
        $url   = $item['link'];
        $date = substr($item['pubdate'],0,26);

        //code to fetch only some text
        $desc = '';
        $max = 30;
        $arr = explode(' ', strip_tags($item['description']));
        $l = count($arr);
        if($l < $max) $max = $l;
        for($j=0;$j<$max;++$j)
        {
            $desc .= $arr[$j] . ' ';
        }
        $desc .= '.....';
        echo "<div class=\"blog\"><a target=\"_blank\" href=$url><h1>$title</h1>$desc<br/><br/>DATED : $date <br/><br/></a></div> ";
        if($i == 3) break; 
    }
}
于 2012-07-07T04:30:28.033 回答