PDA

View Full Version : RSS feed not displaying as html



jccorner
05 Oct 2006, 10:07 AM
I'm using a script to add RSS feeds to my site but unfortunately if the feed returns html, the information is being displayed as text instead of html. Can someone point out to me what I'm missing. Here's the script:



<?php
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
$locations = array('http://rss.news.yahoo.com/rss/topstories');
srand((float) microtime() * 10000000); // seed the random gen
$random_key = array_rand($locations);
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><a href='%s'>%s</a></b></dt>",
trim($link),htmlspecialchars(trim($title)));
printf("<dt>%s</dt><br><br>",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 .= $data;
break;
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
$link .= $data;
break;
}
}
}
?>


Thanks much.

gary[at]castus
24 Oct 2006, 09:59 AM
You will have to supply more information than this. Are you trying to use another site's RSS to fill content on your site? Also, the RSS is simply an XML file you then can do what you like with it. It doesn't just make a web page itself.

The text file that the script is creating is probably right - you just have to do somethihng with it then - like use it as an include on a web page etc.