title: PHP - RSS Parser XML
body: <p>Question: How to Parse <code>&lt;media:content URL="IMG" /&gt;</code> from XML? </p>
  
  <p>OK. This is like asking why 1+1 = 2. And 2+2=Not Available. </p>
  
  <p><strong>Orginal Link:</strong> 
  How to Parse XML With SimpleXML and PHP // By: John Morris. 
  <a href="https://www.youtube.com/watch?v=_1F1Iq1IIS8" rel="nofollow noreferrer">https://www.youtube.com/watch?v=_1F1Iq1IIS8</a></p>
  
  <p>Using his method I can easily reach items on RSS FEED New York Times 
  With Following Code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;How to Parse XML with SimpleXML and PHP&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
  $url = 'http://rss.nytimes.com/services/xml/rss/nyt/Sports.xml';
  $xml = simplexml_load_file($url) or die("Can't connect to URL");
  
  ?&gt;&lt;pre&gt;&lt;?php //print_r($xml); ?&gt;&lt;/pre&gt;&lt;?php
  
  foreach ($xml-&gt;channel-&gt;item as $item) {
      printf('&lt;li&gt;&lt;a href="%s"&gt;%s&lt;/a&gt;&lt;/li&gt;', $item-&gt;link, $item-&gt;title);
  }
  ?&gt;  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>GIVES:<br>
  Sparky Lyle in Monument Park? Fans Say Yes, but He Disagrees<br>
  The Thickly Accented American Behind the N.B.A. in France<br>
  On Pro Basketball: ‘That Got Ugly in a Hurry’: More Playoff Pain Delivered by the Spurs<br>
  ...</p>
  
  <p>BUT</p>
  
  <p>TO reach media:content you cannot use simplexml_load_file as it doesn't grab any media.content tags. </p>
  
  <p>So... Yes.. I searched around on the Webb. 
  I found this example on StackOverflow:<br>
  <a href="https://stackoverflow.com/questions/34541514/get-mediadescription-and-mediacontent-url-from-xml">get media:description and media:content url from xml</a></p>
  
  <p>But using the Code:</p>
  
  <pre><code>&lt;?php
  function feeds() 
  {
      $url = "http://rss.nytimes.com/services/xml/rss/nyt/Sports.xml"; // xmld.xml contains above data
      $feeds = file_get_contents($url);
      $rss = simplexml_load_string($feeds);
      foreach($rss-&gt;channel-&gt;item as $entry) {
           if($entry-&gt;children('media', true)-&gt;content-&gt;attributes()) {
                  $md = $entry-&gt;children('media', true)-&gt;content-&gt;attributes();
                  print_r("$md-&gt;url");
              }
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Gave me no errors. But also a blank page. </p>
  
  <p>And it seems most people (googling) has little to no idea how to really use media:content . So I have to turn for Stackoverflow and hope someone can provide an answer. Im even willing to not use SimpleXML. </p>
  
  <p>What I want.. is .. to grab media:content url IMAGES and use them on a external site. </p>
  
  <p>Also.. if possible. <br>
  I would like to put the XML parsed items into a SQL database. </p>