Note that there are some explanatory texts on larger screens.

plurals
  1. POget data in object - SimpleXML
    text
    copied!<p>So I got a simple function that works, but I'm trying to evolve my experince wtih OOP and try to make sure I can use my code without having to edit everything.</p> <p>Here is my simple function </p> <pre><code>$xmlfeed = file_get_contents('/forum/syndication.php?limit=3'); $xml = new SimpleXMLElement($xmlfeed); $result = $xml-&gt;xpath('channel/item/title'); while(list( , $node) = each($result)) { echo $node; } </code></pre> <p>Now so far I got to this point:</p> <pre><code>class ForumFeed { private function getXMLFeeds($feed = 'all'){ /* Fetch the XML feeds */ $globalFeedXML = file_get_contents('/forum/syndication.php?limit=3'); $newsFeedXML = file_get_contents('/forum/syndication.php?fid=4&amp;limit=3'); /* Turn feed strings into actual objects */ $globalFeed = new SimpleXMLElement($globalFeedXML); $newsFeed = new SimpleXMLElement($newsFeedXML); /* Return requested feed */ if ($feed == 'news') { return $newsFeed; } else if ($feed == 'all') { return $globalFeed; } else { return false; } } public function formatFeeds($feed) { /* Format Feeds for displayable content.. For now we're only interested in the titles of each feed */ $getFeed = $this-&gt;getXMLFeeds($feed); return $getFeed-&gt;xpath('channel/item/title'); } } $feeds = new ForumFeed(); </code></pre> <p>However when trying to <code>echo $feeds-&gt;formatFeeds('all');</code> it doesn't return anything. The results is blank.</p> <p>What am I doing wrong?</p> <p><code>var_dump($feeds-&gt;formatFeeds('all'));</code> returns</p> <pre><code>array(3) { [0]=&gt; object(SimpleXMLElement)#3 (0) { } [1]=&gt; object(SimpleXMLElement)#4 (0) { } [2]=&gt; object(SimpleXMLElement)#5 (0) { } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload