Retrieving RSS feed with tag <content:encoded>

Viewed 34074

I have the following snippet of code:

function getFeed($feed_url) {

$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);

echo "<ul>";

foreach($x->channel->item as $entry) {
    echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
    echo "<li>$entry->content</li>";

echo "</ul>";
}

It works EXCEPT the $entry->content

That part doesn't register. In the actual feed the tag is listed as <content:encoded> but I can't get it to feed. Any suggestions?

6 Answers

The working answer for this is just:

$e_content = $entry->children("content", true);
$e_encoded = (string)$e_content->encoded;

Using SimpleXmlElement or loading via simplexml_load_file you could access it via $entry->children("http://purl.org/rss/1.0/modules/content/")->encoded, just remember to cast it to a string:

foreach($x->channel->item as $entry) {
    echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
    echo "<li>" . (string)$entry->children("http://purl.org/rss/1.0/modules/content/")->encoded . "</li>";

}
Related