另一种方法是如何在网站上显示RSS源? [关闭]

I want to display RSS feeds of a website on my website. This could be easily done by online services like: www.rssinclude.com, www.feedgrabbr.com, etc. But I want the full code... right from the beginning.

For my soccer news website, I use the following code: (Hope, it works)

<?php
class rss 
{
    var $feed;
    function rss($feed) 
    {
        $this->feed = $feed;
    }
    function parse() 
    {
        $rss = simplexml_load_file($this->feed);
    $rss_split = array();
    foreach ($rss->channel->item as $item) {
            $title = (string) $item->title;
                $link   = (string) $item->link;
            $description = (string) $item->description;
                $rss_split[] = '<div>
                                <a href="'.$link.'" target="_blank" title="">'.$title.'</a>
                                <hr>
                                </div>';
        }
        return $rss_split;
    }
    function display($numrows,$head) 
    {
        $rss_split = $this->parse();
        $i = 0;
        $rss_data = '<div class="container">
                     <div class="title">'.$head.'</div>
                     <div class="links">';

        while ( $i < $numrows ) 
    {
                $rss_data .= $rss_split[$i];
                $i++;
        }
        $trim = str_replace('', '',$this->feed);
        $user = str_replace('&lang=en-us&format=rss_200','',$trim);
    $rss_data.='</div></div>';
        return $rss_data;
    }
}

$feedlist = new rss("http://www.fifa.com/rss/index.xml");
echo $feedlist->display(10,"FIFA");
?>

Try Simple XML

<?php
$html = "";
$url = "file.rss";
$xml = simplexml_load_file($url);
for($i = 0; $i < 10; $i++){
    $title = $xml->channel->item[$i]->title;
    $link = $xml->channel->item[$i]->link;
    $description = $xml->channel->item[$i]->description;
    $pubDate = $xml->channel->item[$i]->pubDate;

        $html .= "<a href='$link'><h3>$title</h3></a>";
    $html .= "$description";
    $html .= "<br />$pubDate<hr />";
}
echo $html;
?>

Short Video Tutorial - Youtube