title: Parsing an RSS feed in PHP with DOM
body: <p>I'm trying to create an array of items from an RSS feed. I'm trying to test if it's working by echoing the title of the first item. I've been unsuccessful so far...I'd really appreciate any advice!</p>
  
  <p>I have two files, an 'index.php' and a 'test.php'.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel = "stylesheet" type= "text/css" href = "style.css"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;h1&gt;TEST SLIDER&lt;/h1&gt;
  
  &lt;p&gt;First Title:&lt;br&gt;
  &lt;?php
  
      include 'test.php';
      $NPR_url = 'http://www.npr.org/rss/rss.php?id=1001';
      $NPR = GetFeed($NPR_url);
      echo $NPR[0]['title'];
  
  ?&gt;
  &lt;/p&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and 'test.php'</p>
  
  <pre><code>&lt;?php
  
      function GetFeed($url){
          $feed = new DOMDocument;
          $feed-&gt;load($url);
          $feed_array = array();
  
          foreach($feed-&gt;getElementsByTagName('item') as $story){
              $story_array = array (
                                    'title' =&gt; $story-&gt;getElementsByTagName('title')-&gt;item(0)-&gt;nodeValue,
                                    'desc' =&gt; $story-&gt;getElementsByTagName('description')-&gt;item(0)-&gt;nodeValue,
                                    'link' =&gt; $story-&gt;getElementsByTagName('link')-&gt;item(0)-&gt;nodeValue,
                                    'date' =&gt; $story-&gt;getElementsByTagName('pubDate')-&gt;item(0)-&gt;nodeValue
              );
  
              array_push($feed_array, $story_array);
          }
  
          return $feed_array;
      }
  
  
  ?&gt;
  </code></pre>