0

我怀疑正在显示博客的帖子[超过 1],现在我想根据发布日期显示博客意味着新帖子 1st 下 2nd 等等...我的代码

            require_once('rss_fetch.inc');
            $dateArray= "";
            $urls = array(
            'http://rajs-creativeguys.blogspot.com/feeds/posts/default?alt=rss',
              'http://raghuks.wordpress.com/feed'
            );

            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);
                    $dateArray=array();
                    //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 == 1) break; 
                }
            }

只有最近的 4 个帖子应该从任何博客显示,但应该根据日期请帮助.. 我尝试将所有日期放入数组并使用冒泡排序,但它不起作用.. 请帮助我.. 提前致谢

4

1 回答 1

0
require_once('rss_fetch.inc');
        $dateArray= "";
        $urls = array(
        'http://rajs-creativeguys.blogspot.com/feeds/posts/default?alt=rss',
          'http://raghuks.wordpress.com/feed'
        );
$result_array = array();

        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);
                $dateArray=array();
                //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 .= '.....';
                $tm = strtotime($date);
                $result_array[$tm]['title'] = $title;
                $result_array[$tm]['url'] = $url;
                $result_array[$tm]['desc'] = $desc;
                $result_array[$tm]['date'] = $date;
                if($i == 1) break; 
            }
           ksort($result_array);
           foreach($result_array as $result)
           {
                   echo "<div class=\"blog\"><a target=\"_blank\" href=$result['url']><h1>$result['title']</h1>$result['desc']<br/><br/>DATED : $result['date'] <br/><br/></a></div> ";
           }
        }
于 2012-07-09T07:47:35.493 回答