title: Parsing HTML Table Data from XML with PHP
body: <p>I am somewhat new with PHP, but can't really wrap my head around what I am doing wrong here given my situation.</p>
  
  <p>Problem: I am trying to get the href of a certain HTML element within a string of characters inside an XML object/element via Reddit (if you visit this page, it would be the actual link of the video - not the reddit link but the external youtube link or whatever - nothing else).</p>
  
  <p>Here is my code so far (code updated):</p>
  
  <p>Update: Loop-mania! Got all of the hrefs, but am now trying to store them inside a global array to access a random one outside of this function.</p>
  
  <pre><code>function getXMLFeed() {
      echo "&lt;h2&gt;Reddit Items&lt;/h2&gt;&lt;hr&gt;&lt;br&gt;&lt;br&gt;";
      //$feedURL = file_get_contents('https://www.reddit.com/r/videos/.xml?limit=200');
      $feedURL = 'https://www.reddit.com/r/videos/.xml?limit=200';
      $xml = simplexml_load_file($feedURL);
      //define each xml entry from reddit as an item
      foreach ($xml -&gt; entry as $item ) {
          foreach ($item -&gt; content as $content) {
              $newContent = (string)$content;    
              $html = str_get_html($newContent);
  
              foreach($html-&gt;find('table') as $table) {
                  $links = $table-&gt;find('span', '0');
                  //echo $links;
                  foreach($links-&gt;find('a') as $link) {
                      echo $link-&gt;href;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>XML Code:
  <a href="http://pasted.co/0bcf49e8" rel="nofollow noreferrer">http://pasted.co/0bcf49e8</a></p>
  
  <p>I've also included JSON if it can be done this way; I just preferred XML:
  <a href="http://pasted.co/f02180db" rel="nofollow noreferrer">http://pasted.co/f02180db</a></p>
  
  <p>That is pretty much all of the code. Though, here is another piece I tried to use with DOMDocument (scrapped it).</p>
  
  <pre><code>    foreach ($item -&gt; content as $content) {
         $dom = new DOMDocument();
         $dom -&gt; loadHTML($content);
         $xpath = new DOMXPath($dom);
         $classname = "/html/body/table[1]/tbody/tr/td[2]/span[1]/a";
  
  
  
         foreach ($dom-&gt;getElementsByTagName('table') as $node) {
            echo $dom-&gt;saveHtml($node), PHP_EOL;
            //$originalURL = $node-&gt;getAttribute('href');
         }
  
         //$html = $dom-&gt;saveHTML();
  
      }
  </code></pre>
  
  <p>I can parse the table fine, but when it comes to getting certain element's values (nothing has an ID or class), I can only seem to get ALL anchor tags or ALL table rows, etc.</p>
  
  <p>Can anyone point me in the right direction? Let me know if there is anything else I can add here. Thanks!</p>
  
  <p>Added HTML: 
  I am specifically trying to extract <code>&lt;span&gt;&lt;a href="https://www.youtube.com/watch?v=nZC4mXaosxM"&gt;[link]&lt;/a&gt;&lt;/span&gt;</code> from each table/item.
  <a href="http://pastebin.com/QXa2i6qz" rel="nofollow noreferrer">http://pastebin.com/QXa2i6qz</a></p>