title: Display Title and Image from RSS using php
body: <p>I am trying to create a page that will display the title of an RSS story as well as an image. Every story has a title. Most have an image, but I only need to display the image(s) if they have a height and width set to "100". So far, I haven't had any success filtering the attributes. I'm very new to XML and inexperienced in PHP, but here's what I have so far:</p>
  
  <pre><code>    &lt;? 
      $xml = simplexml_load_file("./_resources/xml/news.rss");
      foreach ($xml-&gt;channel-&gt;item as $key =&gt; $value) {
          echo $value-&gt;title . "&lt;br /&gt;\n";
          $value-&gt;registerXPathNamespace('media','http://search.yahoo.com/mrss/');
          //$result = $value-&gt;xpath('media:thumbnail[@height = "100"]');
          $result = $value-&gt;xpath('media:thumbnail/@url');
          echo '&lt;img src="http:' . $result . '"&gt;' . "&lt;br /&gt;\n";
          }
       ?&gt;
  </code></pre>
  
  <p>The RSS is structured like so:</p>
  
  <pre><code>&lt;channel&gt;
       &lt;title&gt;Title Here&lt;/title&gt;
       &lt;description&gt;Here's the description&lt;/description&gt;
       &lt;content:encode&gt;Here's some content for you&lt;/content:encode&gt;
       &lt;media:thumbnail url="//www.website.com/images/img1.jpg" width="100" height="100" /&gt;
       &lt;media:thumbnail url="//www.website.com/images/img2.jpg" width="150" height="150" /&gt;
  </code></pre>
  
  <p>As you can see, I tried looking for an attribute of height = "100", but had no luck.</p>
  
  <p>I also need to make sure that I don't try to display an image if a 100x100 image isn't present, and make one using simplexml and one using XML/XSL Any tips?</p>
  
  <p>EDIT:
  I THINK I figured it out. It works, at least. Here's what I did:</p>
  
  <pre><code>&lt;? 
      $xml = simplexml_load_file("./_resources/xml/news.rss");
      foreach ($xml-&gt;channel-&gt;item as $key =&gt; $value) {
          echo $value-&gt;title . "&lt;br /&gt;\n";
          $value-&gt;registerXPathNamespace('media','http://search.yahoo.com/mrss/');
          $result = $value-&gt;xpath('media:thumbnail[@height = "100"]/@url');
          if ($result != null){
              echo '&lt;img src="http:' . $result[0] . '"&gt;' . "&lt;br /&gt;\n";
              } else {
                  echo '&lt;img src="./images/noimage.jpg" height="100" width="100"&gt;' . "&lt;br /&gt;\n";
              }
          }
      ?&gt;
  </code></pre>
  
  <p>So, it WORKS... I'm just not sure if it's considered "good code". Also, I'm supposed to do this 2 ways: Using simplexml, and then using XML/XSL. Not sure how to do it with the XML/XSL route, so I could still use a hand there. Thanks!</p>