Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

XML Parser reading html tags

Options
  • 21-07-2010 1:46pm
    #1
    Registered Users Posts: 8,070 ✭✭✭


    [PHP]<post>
    <regular-title>this is another test</regular-title>
    <regular-body><b>oh my lols</b></regular-body>
    </post>
    [/PHP]

    [PHP]<?php
    $insideitem = false;
    $tag = "";
    $title = "";
    $description = "";
    $link = "";

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

    function endElement($parser, $name) {
    global $insideitem, $tag, $title, $description, $link;
    if ($name == "POST") {


    echo $title."<br>";
    echo $description;

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

    function characterData($parser, $data) {

    global $insideitem, $tag, $title, $description, $link;
    if ($insideitem) {

    switch ($tag) {
    case "REGULAR-BODY":
    $description .=$data;
    break;

    case "REGULAR-TITLE":
    $title .= $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("my.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);

    ?>[/PHP]


    case "REGULAR-TITLE":
    works

    case "REGULAR-BODY":
    doesnt

    its because of the <b> tag
    i tried using htmlentities but wont work :/
    cant use SIMPLEXMLLOAD because hosting only has php4 :mad:


Advertisement