Web Analytics Made Easy -
StatCounter rss reader - CodingForum

Announcement

Collapse
No announcement yet.

rss reader

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • rss reader

    Hi there, im thinking of building a rss read script. Since I can't find any example code on the internet.. I'll have to program it all by myself.. I'm wondering though is there any module out there which takes care of reading rss ?

    Note.. im not looking for other sites who offer rss readers, i know they exist
    Msnemo.com - Free winks, emoticons, avatars, moods and lots more for msn and windows live messenger.

  • #2
    Hi.
    Here's an rss feed for Xbox: http://www.xbox.com/en-us/games/rss.xml
    Here's a page that presents that feed: http://bonrouge.com/test/xbox.php
    Here's the code behind that page:

    xboxxml.php
    PHP Code:
    <?php
    $insideitem 
    false;
    $title="";
    $description "";
    $link "";
    $pubdate "";
    $tag ="";

    function 
    startElement($parser$name$attrs) {
    global 
    $insideitem ,$title,$description,$link,$pubdate,$tag;
        if (
    $insideitem) {
            
    $tag $name;
        } elseif (
    $name == "ITEM") {
            
    $insideitem true;
        }
    }

    function 
    endElement($parser$name) {
    global 
    $insideitem ,$title,$description,$link,$pubdate,$tag;
        if (
    $name == "ITEM") {
            
    $pubdate=preg_replace("/00:00:00 GMT/"""$pubdate);

    echo 
    "
        <li><a href=\"
    $link\" class=\"newstitle\">$title</a>
        <ul>
        <li class=\"description\">
    $description</li>
        <li class=\"pubdate\">
    $pubdate</li>
        </ul>
        </li>"
    ;
    $insideitem false;
    $title="";
    $description "";
    $link "";
    $pubdate "";
        }
    }

    function 
    characterData($parser$data) {
    global 
    $insideitem ,$title,$description,$link,$pubdate,$tag;
        if (
    $insideitem) {
        switch (
    $tag) {
            case 
    "TITLE":
            
    $title .= $data;
            break;
            case 
    "DESCRIPTION":
            
    $description .= $data;

            break;
            case 
    "LINK":
            
    $link .= $data;
            break;

            case 
    "PUBDATE":
            
    $pubdate .= $data;
            break;
        }
        }
    }

    $xml_parser xml_parser_create();
    xml_set_element_handler($xml_parser"startElement""endElement");
    xml_set_character_data_handler($xml_parser"characterData");
    $fp fopen("http://www.xbox.com/en-us/games/rss.xml","r")
        or die(
    "Error reading data.");
    while (
    $data fread($fp4096))
        
    xml_parse($xml_parser$datafeof($fp))
            or die(
    sprintf("XML error: %s at line %d"
                
    xml_error_string(xml_get_error_code($xml_parser)), 
                
    xml_get_current_line_number($xml_parser)));
    fclose($fp);
    xml_parser_free($xml_parser);
    ?>
    xbox.php
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>xbox feed</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type="text/css">
    * {
    margin:0;
    padding:0;
    }
    body {
    background-color:white;
    }
    #xbox {
    	list-style:none;
    	margin:auto;
    	width:35em;
    }
    #xbox ul {
    	list-style:none;
    	margin:1em;
    }
    li {
    	margin:0.5em;
    }
    .newstitle {
    	font-weight:bold;
    	color:maroon;
    }
    .description {
    	padding:2px;
    	border:1px solid gray;
    }
    .pubdate {
    	font-size:0.8em;
    	color:gray;
    }
    </style>
    </head>
    <body>
    <ul id="xbox">
    <?php include 'xboxxml.php'; ?>
    </ul>
    </body>
    </html>
    I hope it helps.

    (I adapted this from a Sitepoint tutorial, the address of which I've lost)

    Edit: I've just noticed this is in the Perl/CGI forum and this is neither of those two. I hope that's not a problem...
    Last edited by BonRouge; Oct 6, 2006, 01:40 PM.
    bonrouge

    Comment


    • #3
      Thank you for the code, though my webhosting account doesnt support php as far as i know.. I'm not able to translate it to perl language.. Anyone else ?
      Msnemo.com - Free winks, emoticons, avatars, moods and lots more for msn and windows live messenger.

      Comment


      • #4
        search CPAN:

        http://search.cpan.org/search?query=RSS&mode=all

        Comment


        • #5
          Ok, i've looked into the CGI::Wiki::Plugin::RSS::Reader module...
          I've installed the module on my host and made this little script, however it prints out stuff like this:

          HASH(0x8371af4)HASH(0x8367fa0)HASH(0x8185758)HASH(0x8367fb8)HASH(0x83680cc)HASH(0x8185038)HASH(0x838 5c84)HASH(0x8245eec)HASH(0x8385c6c)HASH(0x8385c60)HASH(0x8385d2c)HASH(0x8385d8c)HASH(0x8385da4)HASH( 0x8385c30)HASH(0x8385e04)HASH(0x8385e7c)HASH(0x8385e40)HASH(0x8385e34)

          What am I doing wrong here ?


          #!/usr/bin/perl
          use CGI;
          $q=new CGI;
          print "Content-Type: text/html; charset=utf-8\n\n";
          use lib "/home/users/web/b2495/hy.mydomain/cgi-bin/";
          require rssRead;
          my $rss = CGI::Wiki::Plugin::RSS::Reader->new(
          url => 'http://www.xbox.com/en-us/games/rss.xml'
          );

          print $rss->retrieve;
          my @items = $rss->retrieve;
          Msnemo.com - Free winks, emoticons, avatars, moods and lots more for msn and windows live messenger.

          Comment


          • #6
            that module also requires:

            LWP::Simple;
            XML::RSS;

            How did you install the module? Why are you using:

            use rssRead;

            instead of:

            use CGI::Wiki::Plugin::RSS::Reader;
            Last edited by KevinADC; Oct 6, 2006, 07:31 PM.

            Comment


            • #7
              never mind, figured it out using xml:arser
              Msnemo.com - Free winks, emoticons, avatars, moods and lots more for msn and windows live messenger.

              Comment

              Working...
              X