Retrieving RSS feed with tag <content:encoded>

kylex picture kylex · Jul 27, 2010 · Viewed 30.3k times · Source

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?

Answer

Artefacto picture Artefacto · Jul 27, 2010

In <content:encoded>, content is the namespace and encoded is the tag name.

You have to use SimpleXMLElement::children. See the output of

var_dump($entry->children("content", true));