I have a script which will grab the info (title, description, and link..)
<?php
$site = "http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml";
$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") {
//echo's the content
//$insert = mysql_query("INSERT INTO `newstest` (`cid`,`title`,`date`,`author`,`story`,`ip`,`from`) VALUES ('1','$title','$date','RSS Bot','$description $link','NO IP','BBC')");
printf("<dt><u><a href='%s'>%s</a></u></dt>",
trim($link),trim($title));
printf("<dd><i>%s</i></dd><br><br>",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("$site","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);
?>
You can see I commented the mysql query to insert it into the database. When uncommented, it posts it, but posts all the articles in the feed. I need it to first check if the article has been posted. Then if it hasn't, post it, and if it already has been posted, don't do anything, and move on to see if the other news has been posted.
Thanks to anyone who can help with figuring this out.
Edited by Corey, 10 May 2007 - 03:05 PM.
