RSS Coding Question ?

Discussion in 'XML & RSS' started by Neale, Dec 3, 2006.

  1. #1
    I have stared at this for a while now and i just cant figure it out
    The code produces two near identical links I would like to get rid of one of them any help much aprechiated.

    <?php


    $file = "http://news.google.com/news?q=san+juan&ie=UTF-8&output=rss";

    $rss_channel = array();
    $currently_writing = "";
    $main = "";
    $item_counter = 9;

    function startElement($parser, $name, $attrs) {
    global $rss_channel, $currently_writing, $main;
    switch($name) {
    case "RSS":
    case "RDF:RDF":
    case "ITEMS":
    $currently_writing = "";
    break;
    case "CHANNEL":
    $main = "CHANNEL";
    break;
    case "IMAGE":
    $main = "IMAGE";
    $rss_channel["IMAGE"] = array();
    break;
    case "ITEM":
    $main = "ITEMS";
    break;
    default:
    $currently_writing = $name;
    break;
    }
    }

    function endElement($parser, $name) {
    global $rss_channel, $currently_writing, $item_counter;
    $currently_writing = "";
    if ($name == "ITEM") {
    $item_counter++;
    }
    }

    function characterData($parser, $data) {
    global $rss_channel, $currently_writing, $main, $item_counter;
    if ($currently_writing != "") {
    switch($main) {
    case "CHANNEL":
    if (isset($rss_channel[$currently_writing])) {
    $rss_channel[$currently_writing] .= $data;
    } else {
    $rss_channel[$currently_writing] = $data;
    }
    break;
    case "IMAGE":
    if (isset($rss_channel[$main][$currently_writing])) {
    $rss_channel[$main][$currently_writing] .= $data;
    } else {
    $rss_channel[$main][$currently_writing] = $data;
    }
    break;
    case "ITEMS":
    if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
    $rss_channel[$main][$item_counter][$currently_writing] .= $data;
    } else {
    $rss_channel[$main][$item_counter][$currently_writing] = $data;
    }
    break;
    }
    }
    }

    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    if (!($fp = fopen($file, "r"))) {
    die("could not open XML input");
    }

    while ($data = fread($fp, 4096)) {
    if (!xml_parse($xml_parser, $data, feof($fp))) {
    die(sprintf("XML error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));
    }
    }
    xml_parser_free($xml_parser);


    if (isset($rss_channel["ITEMS"])) {
    if (count($rss_channel["ITEMS"]) > 0) {
    for($i = 9;$i < count($rss_channel["ITEMS"]);$i++) {
    if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
    print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
    } else {
    print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
    }
    print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />"); }
    } else {
    print ("No News Found");
    }
    }
    ?>
     
    Neale, Dec 3, 2006 IP
  2. Neale

    Neale Peon

    Messages:
    583
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Done a freind solved this over on a nother forum
    just remove this line

    print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
     
    Neale, Dec 5, 2006 IP