0

how can I get the content-Element from XML? Other solutions on stackoverflow could not help me, I'm doing something wrong.. This is how I read the feed:

<?php
            $content = file_get_contents('some feed url');
            $x = new SimpleXmlElement($content);

            foreach($x->channel->item as $entry) {
                $chi = $entry->children('content', true)->encoded;
            }
?>

XML: https://pastebin.com/79dgx8cU

1 Answer 1

1

Try following code:

$x = new SimpleXmlElement($str);
$x->registerXPathNamespace('content', 'http://purl.org/rss/1.0/modules/content/');

$result = $x->xpath('//channel/item/content:encoded');
if(count($result) > 0) {
    foreach($result as $element) {
        echo (string)$element . "\n";
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

You should loop through this $result and cast into string like i did for 0th element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.