I am trying to include a php parser that will retrieve a rss 2.0 file:
<?php
$doc = new DOMDocument();
$doc->load('http://www.domain.com/blog/feed/');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
$itemRSS = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
);
array_push($arrFeeds, $itemRSS);
}
//And trying to parse the return into a template:
$view_doc->assign("DOCID", $arrFeeds);
?>
But the output given is simply “Array” 🙁
I hope that you can give me some hints guys 🙂
Kind Regards!
Remove
$docidtrue = return $arrFeeds;and replace$docidtruewith$arrFeeds. It should work as you wanted.It would look like that:
returnis not what you wanted. Maybe you looked forbreak(which exits the whole current loop) orcontinue(which leaves current loop iteration and goes to the next one).EDIT:
Because you need some string to be passed to
assign()method, we can make something that will display the list of items instead of gathering them for further processing 🙂This has to work 🙂
But remember – what I just did is just wrong. You should parse the variable resulting from the original solution within the template. I have just created it in the wrong place and passed generated string into the view. View is just for transforming data into displayable code (HTML).