2012-05-16 94 views
4

我一直在研究這個話題幾天,現在我仍然不知道如何去做。如何顯示來自其他網站的RSS訂閱源

我想從forexfactory.com獲得一個RSS提要到我的網站,我想對發生的事情做一些格式化,我也想從他們那裏獲得最新的信息(儘管最後兩點可以等待,只要我有一些更多或飼料運行)。

最好我想從頭開始,如果有人知道的教程或我可以使用的東西?

如果不是,我會解決使用第三方API或類似的東西,只要我去做一些工作。

我不確定它是什麼,但有一些關於RSS,我沒有得到,所以如果有人知道任何好,可能基本教程,這將幫助我很多。谷歌搜索的一頁接一頁是很難的。

另外,我不會在JavaScript中輸出它的語言,但PHP或HTML會很棒。

感謝您的幫助。

+1

也許是一個重複的問題。這些已經有很多已被問到。也許這個可以幫助你? http://stackoverflow.com/questions/2074795/getting-rss-feeds-on-website 也許不是你在找什麼,但特別是,SimplePie插件是偉大的。 http://simplepie.org/ –

+0

我在寫這篇文章時沒有遇到過這個問題。我在看Simlepie,公平地說,我認爲這可能是我正在尋找的。 @LiamSpencer – ragebunny

+0

不錯的一個!我給你添了一個答案。祝你好運。 –

回答

3

它看起來像SimplePie可能是你在找什麼。這是一個非常基本的RSS插件,它非常易於使用並且可以自定義。您可以從the website下載。

如果您願意,您可以使用它的bare bones或者您可以使用delve deeper插入插件。這是他們網站上的demo

+1

令人驚歎!非常感謝好友! – ragebunny

+0

沒問題的人!樂意效勞。 –

2

的index.php

include('rss_class.php'); 

    $feedlist = new rss($feed_url); 
    echo $feedlist->display(2,"Feed Title"); 

rss_class.php

<?php 
class rss { 
     var $feed; 
     function rss($feed){ 
      $this->feed = $feed; 
     } 

     function parse(){ 
      $rss = simplexml_load_file($this->feed); 

      //print_r($rss);die; /// Check here for attributes 

      $rss_split = array(); 

      foreach ($rss->channel->item as $item) { 

       $title = (string) $item->title; 
       $link = (string) $item->link; 
       $pubDate = (string) $item->pubDate; 
       $description = (string) $item->description; 
       $image = $rss->channel->item->enclosure->attributes(); 
       $image_url = $image['url']; 

      $rss_split[] = ' 
        <li> 
         <h5><a href="'.$link.'">'.$title.'</a></h5> 
         <span class="dateWrap">'.$pubDate.'</span> 
         <p>'.$description.'</p> 
         <a href="'.$link.'">Read Full Story</a> 
        </li> 
       '; 
      } 
      return $rss_split; 
     } 

     function display($numrows,$head){ 

      $rss_split = $this->parse(); 
      $i = 0; 
      $rss_data = '<h2>'.$head.'</h2><ul class="newsBlock">'; 
      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.='</ul>'; 

      return $rss_data; 
     } 
} 
?> 
0

我沒有納入< TABLE>標記有可能是你想顯示一個以上的文章。

class RssFeed 
{ 
    public $rss = ""; 

    public function __construct($article) 
    { 
     $this->rss = simplexml_load_file($article, 'SimpleXMLElement', LIBXML_NOERROR | LIBXML_NOWARNING); 

     if($this->rss != false) 
     { 
     printf("<TR>\r\n"); 
     printf("<TD>\r\n"); 
     printf("<h3>%s</h3>\r\n", $this->rss->channel->title); 
     printf("</TD></TR>\r\n"); 

     foreach($this->rss->channel->item as $value) 
     { 
      printf("<TR>\r\n"); 
      printf("<TD id=\"feedmiddletd\">\r\n"); 
      printf("<A target=\"_blank\" HREF=\"%s\">%s</A><BR/>\r\n", $value->link, $value->title); 
      printf($value->description); 
      printf("</TD></TR>\r\n"); 
     } 
     } 
    } 
}