Integrating RSS feed into a website..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mayhem

    Integrating RSS feed into a website..

    I would like to integrate an RSS newsfeed into my website but can't
    seem to figure out how.
    Has anyone got any pointers for me?

    E.
  • Brendan Donahue

    #2
    Re: Integrating RSS feed into a website..

    Mayhem wrote:
    [color=blue]
    > I would like to integrate an RSS newsfeed into my website but can't
    > seem to figure out how.
    > Has anyone got any pointers for me?
    >
    > E.[/color]
    Yeah, search http://google.com and http://php.net for "PHP XML" or "PHP RSS
    PARSING". There are dozens of sites that will tell you how to do this
    already out there.

    Comment

    • Terence

      #3
      Re: Integrating RSS feed into a website..

      Mayhem wrote:
      [color=blue]
      > I would like to integrate an RSS newsfeed into my website but can't
      > seem to figure out how.
      > Has anyone got any pointers for me?
      >
      > E.[/color]

      use XSLT.

      You will need to write an XSL template to convert the raw RSS formatted
      XML into whatever HTML you want.

      This might work:

      $xh = xslt_create();
      $html = xslt_process($x h, 'http://theSource/info.rss', 'rss2xhtml.xsl' );
      echo $html;

      You will obviously have to provide 'rss2xhtml.xsl' . See zvon.org for
      tutorials and a crash course in writing XSLT templates.

      don't concern yourself with parsing RSS. XML parsing built into the XSLT
      processor will be enough for your needs.

      If you're struggling with XSLT, join this mailing list, they are very
      helpful. http://www.mulberrytech.com/xsl/xsl-list/index.html

      Once you can do basic XML/XSLT transformations , you'll wonder how you
      ever lived without it.

      Also, if you're lazy ;)
      you might want to check this out
      2RSS.com :: RSS feeds, RSS directory, RSS software, RSS scripts, RSS articles, RSS syndication, XML, RDF, news

      Comment

      • marathon

        #4
        Re: Integrating RSS feed into a website..

        On Thu, 22 Apr 2004 23:15:41 +0200, Mayhem in comp.lang.php wrote:[color=blue]
        >I would like to integrate an RSS newsfeed into my website but can't
        >seem to figure out how.
        >Has anyone got any pointers for me?[/color]

        I had the same issue a few weeks ago. Using Google, I found a snippet which I
        adapted to my needs. Here's something you might be able to work with;

        <?php
        $_item = array();
        $_depth = array();
        $_tags = array("dummy");

        function initArray()
        {
        global $_item;

        $_item = array ("TITLE"=>"" , "LINK"=>"",
        "DESCRIPTION"=> "", "URL"=>"");
        }

        function startElement($p arser, $name){
        global $_depth, $_tags, $_item;

        if (($name=="ITEM" ) ||
        ($name=="CHANNE L")
        || ($name=="IMAGE" )) {
        initArray();
        }
        @$_depth[$parser]++;
        array_push($_ta gs, $name);
        }

        function endElement($par ser, $name){
        global $_depth, $_tags, $_item;

        array_pop($_tag s);
        $_depth[$parser]--;
        switch ($name) {
        case "ITEM":
        echo "<p><a href=\"{$_item['LINK']}
        \">" .
        "{$_item['TITLE']}</a></p>\n";
        initArray();
        break;

        case "IMAGE":
        echo "<a href=.{$_item['LINK']}.>" .
        "<DEFANGED_ IMG src=.{$_item
        ['URL']}. " .
        "alt=.{$_it em['TITLE']};
        border=.0.></a>\n<br />\n";
        initArray();
        break;

        case "CHANNEL":
        echo "<h3>{$_ite m['TITLE']}</h3>\n";
        initArray();
        break;
        }
        }

        function parseData($pars er, $text){
        global $_depth, $_tags, $_item;

        $crap = preg_replace ("/\s/", "", $text);
        /* is the data just whitespace?
        if so, we don't want it! */

        if ($crap) {
        $text = preg_replace ("/^\s+/", "", $text);
        /* get rid of leading whitespace */
        if (@$_item[$_tags[$_depth[$parser]]]) {
        $_item[$_tags[$_depth[$parser]]] .=
        $text;
        } else {
        $_item[$_tags[$_depth[$parser]]] =
        $text;
        }
        }
        }

        function parseRDF($file) {
        global $_depth, $_tags, $_item;

        $xml_parser = xml_parser_crea te();
        initArray();

        /* Set up event handlers */
        xml_set_element _handler
        ($xml_parser, "startEleme nt", "endElement ");
        xml_set_charact er_data_handler
        ($xml_parser, "parseData" );

        /* Open up the file */
        $fp = fopen ($file, "r") or die ("Could not
        open $file for input");

        while ($data = fread ($fp, 4096)) {
        if (!xml_parse($xm l_parser, $data, feof
        ($fp))) {
        die (sprintf("XML error: %s at line %d",
        xml_error_strin g(xml_get_error _code
        ($xml_parser)),
        xml_get_current _line_number
        ($xml_parser))) ;
        }
        }

        fclose($fp);
        xml_parser_free ($xml_parser);
        }

        parseRDF
        ("http://freshmeat.net/backend/fm-releases.rdf");
        #("http://www.theregister .co.uk/headlines.rss") ;
        ?>

        <br />
        <h2>Latest Headlines From Newsforge</h2>
        <?php
        /* declare different RSS feed. Since the code to parse source is
        * already listed, all one needs to do is list the new source as
        * follows*/
        parseRDF("http://www.newsforge.c om/newsvac.rss");

        Replace the last line, with whatever source you wish to parse.

        There are some varations out there, were one can cache the file in a dbase, so
        that each time teh page is loaded it doesn't hit the remote server everytime.
        But, I'll leave that as an exercise for you to find. ;)

        HTH.

        --
        S.Allen
        -------------------------------------------
        barnyard Sunday Apr 25 2004 11:10:02 PM EDT
        -------------------------------------------
        Ver o que é justo e não agir com justiça é a maior das covardias
        humanas.
        -- Confúcio

        Comment

        • Tim Van Wassenhove

          #5
          Re: Integrating RSS feed into a website..

          In article <slrnc8ovt9.g0s .M@barnyard.swe etpig.dyndns.or g>, marathon wrote:[color=blue]
          > On Thu, 22 Apr 2004 23:15:41 +0200, Mayhem in comp.lang.php wrote:[color=green]
          >>I would like to integrate an RSS newsfeed into my website but can't
          >>seem to figure out how.
          >>Has anyone got any pointers for me?[/color]
          >
          > I had the same issue a few weeks ago. Using Google, I found a snippet which I
          > adapted to my needs. Here's something you might be able to work with;[/color]

          [snip code]

          Or you could simply use the code at http://magpierss.sf.net

          Comment

          • mail@page-zone.com

            #6
            Re: Integrating RSS feed into a website..

            I set up an rss feed then documented exactly how I did it on this page:

            It definitely isn't the only way or the best way, but it works.

            Comment

            Working...