RSS feed displaying too many items

Discussion in 'XML & RSS' started by crafty, Feb 3, 2006.

  1. #1
    Hi

    I have been using the following code to display RSS feeds on my sites for some time, but it is displaying 26 items, and I am concerned that this may be making the sites load slowly for some people.

    Is there part of it that I can modify to limit the number of items that it displays? Any help would be appreciated.
    Incidently, the code was initially provided by a member here but unfortunately I have lost their details.
    Thanks
    Tony

    <?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://www.ezinearticles.com/rss/Health-and-Fitness-Beauty.xml',"r")
    or die("Error reading RSS data.");
    while ($data = fread($fp, 4096))
    xml_parse($xml_parser, $data, feof($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);
    ?>
    </DIV>

    http://www.paralegalcoursesonline.com
     
    crafty, Feb 3, 2006 IP