Results 1 to 3 of 3

Thread: Simple RSS Reader Script

  1. #1
    Join Date
    Sep 2004
    Location
    Martil
    Age
    31
    Posts
    18,723
    Likes (Given)
    0
    Likes (Received)
    457
    Dislikes (Given)
    0
    Dislikes (Received)
    0
    Rep Power
    109883

    Default Simple RSS Reader Script

    Here is a script that you can use to read rss feeds, please take note this script dont work to atom.xml.

    You can modify or tweak this script to make it more powerful. Use the first script if you plan to use single rss feed only and the second code if you plan to rotate a feed.

    To make this rss feed reader work, you need to replace the rss feed url with the source you want.

    PHP Code:
    <?php
    $insideitem 
    false;
    $tag "";
    $title "";
    $description "";
    $link "";
    function 
    startElement($parser$name$attrs) {
    global 
    $insideitem$tag$title$description$link;
    if (
    $insideitem) {
    $tag $name;
    } elseif (
    $name == "ITEM") {
    $insideitem true;
    }
    }
    function 
    endElement($parser$name) {
    global 
    $insideitem$tag$title$description$link;
    if (
    $name == "ITEM") {
    printf("<dt><b><a href=%s>%s</a></b></dt>",
    trim($link),htmlspecialchars(trim($title)));
    printf("<dt>%s</dt><br><br>",htmlspecialchars(trim($description)));
    $title "";
    $description "";
    $link "";
    $insideitem false;
    }
    }
    function 
    characterData($parser$data) {
    global 
    $insideitem$tag$title$description$link;
    if (
    $insideitem) {
    switch (
    $tag) {
    case 
    "TITLE":
    $title .= $data;
    break;
    case 
    "DESCRIPTION":
    $description .= $data;
    break;
    case 
    "LINK":
    $link .= $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://michaelthompson.org/news/goo-world.xml","r")
    or die(
    "Error reading RSS 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);
    ?>
    The second script

    PHP Code:
    <?php
    $insideitem 
    false;
    $tag "";
    $title "";
    $description "";
    $link "";
    $locations = array(http://michaelthompson.org/news/goo-world.xml, http://forums.seochat.com/external.php, http://michaelthompson.org/news/goo-world.xml);
    srand((float) microtime() * 10000000); // seed the random gen
    $random_key array_rand($locations);
    function 
    startElement($parser$name$attrs) {
    global 
    $insideitem$tag$title$description$link;
    if (
    $insideitem) {
    $tag $name;
    } elseif (
    $name == "ITEM") {
    $insideitem true;
    }
    }
    function 
    endElement($parser$name) {
    global 
    $insideitem$tag$title$description$link;
    if (
    $name == "ITEM") {
    printf("<dt><b><a href=%s target=new>%s</a></b></dt>",
    trim($link),htmlspecialchars(trim($title)));
    printf("<dt>%s</dt><br><br>",htmlspecialchars(trim($description)));
    $title "";
    $description "";
    $link "";
    $insideitem false;
    }
    }
    function 
    characterData($parser$data) {
    global 
    $insideitem$tag$title$description$link;
    if (
    $insideitem) {
    switch (
    $tag) {
    case 
    "TITLE":
    $title .= $data;
    break;
    case 
    "DESCRIPTION":
    $description .= $data;
    break;
    case 
    "LINK":
    $link .= $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($locations[$random_key], r)
    or die(
    "Error reading RSS 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);
    ?>
    -
    -


    **FAQ**

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ]


  2.    Advertissements


  3. #2
    Join Date
    Oct 2008
    Age
    28
    Posts
    9
    Likes (Given)
    0
    Likes (Received)
    0
    Dislikes (Given)
    0
    Dislikes (Received)
    0
    Rep Power
    10

    Default

    thank you for your sharing

  4. #3
    Join Date
    Sep 2012
    Location
    Vancouver
    Posts
    1
    Likes (Given)
    0
    Likes (Received)
    0
    Dislikes (Given)
    0
    Dislikes (Received)
    0
    Rep Power
    10

    Default

    Your simple rss reader script looks like what I have been searching for to put on my html website (still in development). I have one of the main links that I will be using but I am not sure how to modify the script for number of items, colors, etc. Also I believe that something has to be loaded up to my eventual server but I don't know exactly what that is. Can you help or point me in the right direction? Thanks.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •