How to display RSS feeds from other sites

徘徊边缘 提交于 2019-12-01 05:34:00

问题


I have been researching this topic for a few days now and i'm still non the wiser as on how to do it.

I want to get an RSS feed from forexfactory.com to my website, i want to do some formatting on whats happening and i also want the latest information from them (Although those last two points can wait as long as i have some more or feed running).

Preferably I'd like to develop this from the ground up if anyone knows of a tutorial or something i could use?

If not i will settle for using a third party API or something like that as long as i get to do some of the work.

I'm not sure what it is but there is something about RSS that i'm not getting so if anyone knows of any good, probably basic tutorials that would help me out a lot. It's kind of hard going through page after page of google searches.

Also i'm not to fussed on the language it's outputted in Javascript, PHP or HTML will be great though.

Thanks for the help.


回答1:


It looks like SimplePie may be what you are looking for. It's a very basic RSS plugin which is quite easy to use and is customisable too. You can download it from the website.

You can use it at it's bare bones or you can delve deeper in to the plugin if you wish. Here's a demo on their website.




回答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;
        }
}
?>



回答3:


I didn't incorporate the < TABLE > tags as there might be more than one article that you would like to display.

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");
        }
      }
    }
}


来源:https://stackoverflow.com/questions/10615635/how-to-display-rss-feeds-from-other-sites

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!