2012-05-16 110 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"); 
     } 
     } 
    } 
}