grabfeed
This php script will get feeds from a list of sites you define.
<?php
/*************************************
GRABFEED v1.0
project: CSS HEAVEN (cssheaven.com)
usage:
Paste <? include ("grabfeed.php"); ?>
where you want feeds to display
*************************************/
/* listing fresh feeds */
$rss = array(
"http://www.solucija.com/rss.xml",
"http://andreasviklund.com/feed/",
"http://www.cssbeauty.com/rss/news/", "http://www.cssplay.co.uk/feed.xml",
"http://p-ahlqvist.com/rss.xml");
/*************************************/
foreach ($rss as $file) {
set_time_limit(0);
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;
$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
if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) {
for($i = 0;$i < 1;$i++) {
if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
echo "<p><a title='Read Full Article' href=""
. $rss_channel["ITEMS"][$i]["LINK"] . "">"
. $rss_channel["ITEMS"][$i]["TITLE"] . "</a><br />";
} else {
echo "<p>" .$rss_channel["ITEMS"][$i]["TITLE"]. "<br />";
}
echo substr($rss_channel["ITEMS"][$i]["DESCRIPTION"], 0, 67) . "...</p>"; }
} else {
echo "<b>There are no articles in this feed.</b>";
}
}}
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;
}
}
}
?>
Download - grabfeed.zip
06.12.2006. 14:00
