Below is my code for parsing a remote .rss file. I have uploaded this to my server I get zero errors but the data is not displayed. I cant find the misconfiguration that is eluding me, perhaps another pair of eyes will help, having a fresh view of it. Any help is appreciated, thank you.
Here is the code:
<?php
mysql_connect ("localhost", "techa_admin", "reaper") or die ('I cannot connect to the database.');
mysql_select_db ("techa_");
class xItem {
var $xTitle;
var $xLink;
var $xDescription;
}
// general vars
$sTitle = "";
$sLink = "";
$sDescription = "";
$arItems = array();
$itemCount = 0;
// ****** Start User-Defined Vars ******
// rss url goes here
$uFile = "http://www.camelotherald.com/xml/news.rss";
// descriptions (true or false) goes here
$bDesc = true;
// font goes here
$uFont = "Verdana, Arial, Helvetica, sans-serif";
$uFontSize = "2";
// *** End User-Defined Vars ***********
function startElement($parser, $name, $attrs) {
global $curTag;
$curTag .= "$name";
}
function endElement($parser, $name) {
global $curTag;
$caret_pos = strrpos($curTag,'');
$curTag = substr($curTag,0,$caret_pos);
}
function characterData($parser, $data) { global $curTag; // get the Channel information first
global $sTitle, $sLink, $sDescription;
$titleKey = "RSSCHANNELTITLE";
$linkKey = "RSSCHANNELLINK";
$descKey = "RSSCHANNELDESCRIPTION";
if ($curTag == $titleKey) {
$sTitle = $data;
}
elseif ($curTag == $linkKey) {
$sLink = $data;
}
elseif ($curTag == $descKey) {
$sDescription = $data;
}
// now get the items
global $arItems, $itemCount;
$itemTitleKey = "RSSCHANNELITEMTITLE";
$itemLinkKey = "RSSCHANNELITEMLINK";
$itemDescKey = "RSSCHANNELITEMDESCRIPTION";
if ($curTag == $itemTitleKey) {
// make new xItem
$arItems[$itemCount] = new xItem();
// set new item object's properties
$arItems[$itemCount]->xTitle = $data;
}
elseif ($curTag == $itemLinkKey) {
$arItems[$itemCount]->xLink = $data;
}
elseif ($curTag == $itemDescKey) {
$arItems[$itemCount]->xDescription = $data;
// increment item counter
$itemCount++;
}
}
// main loop
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen($uFile,"r") or die ("could not open RSS for 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);
// write out the items
?>
<head>
<title><?php echo ($sDescription); ?></title>
<meta name = "description" content = "<?php echo ($sDescription); ?>">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor = "#333333">
<font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><a href = "<?php echo($sLink); ?>"><?php echo($sTitle); ?></a></font>
<br>
<br>
<?php
for ($i=0;$i<count($arItems);$i++) {
$txItem = $arItems[$i];
?>
<font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><a href = "<?php echo($txItem->xLink); ?>"><?php echo($txItem->xTitle); ?></a></font>
<br>
<?php
if ($bDesc) {
?>
<font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><?php echo ($txItem->xDescription); ?>
<br>
<?php
}
echo ("<br>");
}
?>
</body>