Associate
- Joined
- 29 Mar 2004
- Posts
- 593
- Location
- Cambs, UK
Hi all,
Could someone please tell me how I could get this script (see below) to read through another rss feed. I cant seem to figure it out.
Cheers in advance,
I would like to read another feed as well as the front page feed. A feed such as the technology feed: http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml
Edward
Could someone please tell me how I could get this script (see below) to read through another rss feed. I cant seem to figure it out.
Cheers in advance,
PHP:
<?php
$count=0;
$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, $count;
if($count<4){
if ($name == "ITEM") {
echo "<a href='$link'>$title</a><br/>";
$title = "";
$description = "";
$link = "";
$insideitem = false;
$count++;
}}
}
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://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.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);
?>
I would like to read another feed as well as the front page feed. A feed such as the technology feed: http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml
Edward