hi,
this is php code that i use to extract feed content.
<?
$url = 'http://feeds.feedburner.com/ProbloggerHelpingBloggersEarnMoney'; // example feed
$fp = fopen($url,"r");
while (!feof ($fp))
$xml .= fgets($fp, 4096);
fclose ($fp);
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;
$file=$url;
$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("ERROR");
while ($data = fread($fp, 4096)) {
if(!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML ERROR: %s - %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
$n=count($rss_channel["ITEMS"]);
for($k = 0;$k < $n;$k++) {
$newsurl[$k] = $rss_channel["ITEMS"][$k]["LINK"];
$newstitle[$k] = $rss_channel["ITEMS"][$k]["TITLE"];
$newsdescription[$k] = $rss_channel["ITEMS"][$k]["DESCRIPTION"];
}
for($i=0;$i<$n;$i++){
echo $newstitle[$i].' - '.$newsurl[$i].'<br />'.$newsdescription[$i].'<br /><br />';
}
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;
}
}
}
?>
it works ok so far, but problem is that it doesnt show full description. it actually takes description tag content from feed, but usually that is just part of content. im not the author of this script so i dont quite understand what needs to be changed in it, so that it would extract full content.
what it does, it takes content of <description> tag
<description><![CDATA[part of text]]></description>
<content:encoded><![CDATA[full text]]></content:encoded>
but what i want to do is - check if there is data in <content:encoded>, if yes, then take that as content, if no then use <description> content.
any thoughts on how to do that? or maybe you got some links where i can find script that would work for me?