Remove RSS Links

viper

BANNED
Joined
Nov 15, 2007
Messages
165
Reaction score
36
maybe someone needs this. the code gets the rss xml feed and strips them. in this code;
- i removed the links to external pages
- i shuffled them so that they dun appear in their designated feed
- $max_news will set the number of feeds i want to appear. setting it at 0 will display 1 feed
- used them after a para or article so its like part of it.

i didnt write the codes, amended it though to fit my needs. in fact i just started using them again with the crap that im facing. its in php.

i apologise if it is wrong to be posting this. i would have attached it but the requirement for rep would make it very difficult for most to share. i shd know as im having difficulty downloading some of the interesting stuffs lately. anyways i hope its useful to someone.

<?
set_time_limit(0);

$file = "http://url-of-xml";
$max_news = 0;

$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;

function startElement($parser, $name, $attrs) {
global $rss_channel, $currently_writing, $main;
switch($name) {
case "RSS":
case "RDF:RDF":
case "ITEMS":
$currently_writing = "";
break;
case "CHANNEL":
$main = "CHANNEL";
break;
case "IMAGE":
$main = "IMAGE";
$rss_channel["IMAGE"] = array();
break;
case "ITEM":
$main = "ITEMS";
break;
default:
$currently_writing = $name;
break;
}
}

function endElement($parser, $name) {
global $rss_channel, $currently_writing, $item_counter;
$currently_writing = "";
if ($name == "ITEM") {
$item_counter++;
}
}

function characterData($parser, $data) {
global $rss_channel, $currently_writing, $main, $item_counter;
if ($currently_writing != "") {
switch($main) {
case "CHANNEL":
if (isset($rss_channel[$currently_writing])) {
$rss_channel[$currently_writing] .= $data;
} else {
$rss_channel[$currently_writing] = $data;
}
break;
case "IMAGE":
if (isset($rss_channel[$main][$currently_writing])) {
$rss_channel[$main][$currently_writing] .= $data;
} else {
$rss_channel[$main][$currently_writing] = $data;
}
break;
case "ITEMS":
if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
} else {
$rss_channel[$main][$item_counter][$currently_writing] = $data;
}
break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML 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);

// output HTML
// $rssfeed = "<div class=\"channelname\"><strong>" . $rss_channel["TITLE"] . "</strong></div>";
// $rssfeed = $rssfeed."<div class=\"channeldescription\"><strong>" . $rss_channel["DESCRIPTION"] . "</strong></div><br />";
if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) {
shuffle($rss_channel["ITEMS"]);
for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
//print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
//print ("\n<div class=\"itemtitle\"><strong>" . $rss_channel["ITEMS"][$i]["TITLE"] . "</strong></div>");
$rsstitle = "\n<div class=\"\"><strong>" . $rss_channel["ITEMS"][$i]["TITLE"] . "</strong></div>";
} else {
$rsstitle = "\n<div class=\"\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>";
}
$rssfeed = $rssfeed."<div class=\"\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />";

if($i==$max_news){
break;
}

}

} else {
$rssfeed = "<b>There are no articles in this feed.</b>";
}


}
?>
 
Back
Top