WordPress.org

Ready to get started?Download WordPress

Forums

Trouble parsing RSS feed (1 post)

  1. pwhite
    Member
    Posted 8 years ago #

    Hi,

    I have my page
    http://imafish.co.uk/index2.php
    and for some reason all of the ' and " are coming up as strange characters.

    My PHP code for the RSS feed is:

    <?php

    $insideitem = false;
    $tag = "";
    $title = "";
    $description = "";
    $link = "";

    //start of rss functions
    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>%s</b></dt>",
    htmlspecialchars(trim($link)),htmlspecialchars(trim($title)));
    printf("<dd>%s</dd>",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 .= htmlspecialchars($data);
    break;
    case "DESCRIPTION":
    $description .= $data;

    break;
    case "LINK":
    $link .= $data;
    break;
    }
    }
    }
    //end of rss functions

    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    $fp = fopen("http://imafish.co.uk/blog/feed/","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);

    ?>

    Any suggestions? thanks

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags