tags:

views:

163

answers:

2

I have used several different scripts that people have suggested for trying to parse RSS including Magpie and the SimpleXML feature in PHP. But none seem to handle RSS 2.0 well because they will not give me back the full content chunk. Does anyone have a suggestion for reading a feed like the one found at http://chacha102.com/feed/, and getting the full content instead of only the description?

+1  A: 

Without reading any documentation of the rss "content" namespace and how it is to be used, here is a working SimpleXML script. The trick is using the namespace when retreiving the content.

/* the namespace of rss "content" */
$content_ns = "http://purl.org/rss/1.0/modules/content/";

/* load the file */
$rss = file_get_contents("http://chacha102.com/feed/");
/* create SimpleXML object */
$xml = new SimpleXMLElement($rss);
$root=$xml->channel; /* our root element */

foreach($root->item as $item) { /* loop over every item in the channel */
    print "Description: <br>".$item->description."<br><br>";
    print "Full content: <div>";
    foreach($item->children($content_ns) as $content_node) {
        /* loop over all children in the "content" namespace */
        print $content_node."\n";
    }
    print "</div>";
}
gnud
A: 

What do you have that's not working right now? Parsing RSS should be a trivial process. Try stepping back from excessive libraries and just use a few simple XPath queries or accessing the DOMDocument object in PHP.

see: PHP DOMDocument

uidzer0