Code to show RSS feed froma different website

Discussion in 'HTML & Website Design' started by haxor1980, Jul 14, 2008.

  1. #1
    hello,

    I would like to show RSS feed from a website say http://www.haxor.com on the front page of my website. Can some one help me in accomplishing this?
     
    haxor1980, Jul 14, 2008 IP
  2. itcn

    itcn Well-Known Member

    Messages:
    795
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    118
    #2
    itcn, Jul 14, 2008 IP
  3. haxor1980

    haxor1980 Banned

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hey thanks for the reply, but that is not going to serve my purpose and implementing that will be too difficult. Ther must be some easier way. if any one has any other suggestion, please help me.
     
    haxor1980, Jul 14, 2008 IP
  4. bavington

    bavington Peon

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you convert your web page to .asp extension and use this simple all in one ASP Script.

    Simple Replace the 'URLToRSS with a full feed address.

    I have set this code up so it pulls just the title of posts into bullet points.

    You can add in the other variables to add more information etc.

    Let me know if you need any more help configuring.

    :

     
    bavington, Jul 14, 2008 IP
  5. itcn

    itcn Well-Known Member

    Messages:
    795
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    118
    #5
    Too hard? It looks easier than the ASP version :) Just copy and paste this code change only 1 line, the part which says "YOURFEEDURLHERE"
    It also definitely serves your purpose. It takes an RSS feed from another website and prints it in HTML on your web page.

    
    Listing C: Parsing the RSS file 
     
     
    <?php
      $GLOBALS['title'] = false;
      $GLOBALS['link']  = false;
      $GLOBALS['description'] = false;
      $GLOBALS['titletext'] = null;
      $GLOBALS['linktext'] = null;
      $GLOBALS['desctext'] = null;
     
      function startElement( $parser, $tagName, $attrs ) {
        switch( $tagName ) {
          case 'TITLE':
            $GLOBALS['title'] = true;
            break;
          case 'LINK':
            $GLOBALS['link'] = true;
            break;
          case 'DESCRIPTION':
            $GLOBALS['description'] = true;
            break;
        }
      }
     
      function endElement( $parser, $tagName ) {
    
        switch( $tagName ) {
          case 'TITLE':
            echo "<p><b>" . $GLOBALS['titletext'] . "</b><br/>";
            $GLOBALS['title'] = false;
            $GLOBALS['titletext'] = "";
            break;
          case 'LINK':
            echo "Link: <a href=\"". $GLOBALS['linktext'] . "\">" . $GLOBALS['linktext'] . "</a><br/>";
            $GLOBALS['link'] = false;
            $GLOBALS['linktext'] = "";
            break;
          case 'DESCRIPTION':
            echo "Desc: " . $GLOBALS['desctext'] . "</p>";
            $GLOBALS['description'] = false;
            $GLOBALS['desctext'] = "";
            break;
        }
      
      }
     
    
      function charElement( $parser, $text ) {
        if( $GLOBALS['title'] == true ) {
            $GLOBALS['titletext'] .= htmlspecialchars( trim($text) );
        } else if( $GLOBALS['link'] == true ) {
            $GLOBALS['linktext']  .= trim( $text );
        } else if( $GLOBALS['description'] == true ) {
            $GLOBALS['desctext'] .= htmlspecialchars( trim( $text ) );
        }
      }
     
    
      $xmlParser = xml_parser_create();
     
      
    
      xml_set_element_handler( $xmlParser, "startElement", "endElement" );
     
      
      xml_set_character_data_handler( $xmlParser, "charElement" );
     
     
      $fp = fopen( "http://YOURFEEDURLHERE", "r" ) or die( "Cannot read RSS data file." );
        
      while( $data = fread( $fp, 4096 ) ) {
        xml_parse( $xmlParser, $data, feof( $fp ) );
      }
      
     
      fclose( $fp );
     
     
      xml_parser_free( $xmlParser );
     
    ?>
     
    
    
    Code (markup):
     
    itcn, Jul 14, 2008 IP
  6. ozan

    ozan Peon

    Messages:
    82
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I've used Magpie RSS [http://magpierss.sourceforge.net/] in the past with good results.

    Unlike other php XML parsers, it doesn't break when you feed it unusual (invalid) XML files.
     
    ozan, Jul 14, 2008 IP
  7. bavington

    bavington Peon

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks itcn, Thats a good PHP version, better than my ASP one. I justed tested it out and it works.
     
    bavington, Jul 14, 2008 IP
  8. Highwayman

    Highwayman Peon

    Messages:
    117
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Likewise, except I found magpie stopped working for me. However, by submitting my feed to Feedburner the rss started working again. So if you use magpie, I recommend using Feedburner aswell.
     
    Highwayman, Jul 14, 2008 IP
  9. haxor1980

    haxor1980 Banned

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Let me try both ITCN and Ozan's suggestion. I will write back the result for both here.
     
    haxor1980, Jul 14, 2008 IP
  10. edetroiter

    edetroiter Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    If you go to itde.vccs.edu/rss2js/build.php it will convert the feed address into the code to place in your web page.
     
    edetroiter, Jul 14, 2008 IP
  11. haxor1980

    haxor1980 Banned

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    @ Edetroiter

    U r right, beside ur link I found a couple of other links and infact these are really the best solution.

    I hv also bough the CARP Evolution that converts any RSS feed and display it as content with images and video on ur webpage. This is real good man.

    let me know if any one wish to buy it.
     
    haxor1980, Jul 14, 2008 IP
  12. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #12
    There is also the excellent lastRSS rss parser. It's simple to setup, and very light. I use it on a ton of sites and it's never let me down once.

    http://lastrss.oslab.net/
     
    Kerosene, Jul 14, 2008 IP