title: Get first image with new DOMDocument()
body: <p>I am trying to get the first image of some HTML. I know how to achieve all images, using a for loop. However, I am struggling to get <strong>just</strong> the first.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>function get_first_image_b() {
  
      global $post, $posts;
      ob_start();
      ob_end_clean();
      $html= $post-&gt;post_content;
  
      $doc = new DOMDocument();
      @$doc-&gt;loadHTML($html);
      $img = $doc-&gt;getElementsByTagName('img');
      print_r($img);
  
  }
  </code></pre>
  
  <p>Which spits out:</p>
  
  <pre><code>(
      [length] =&gt; 4
  )
  </code></pre>
  
  <p>Would anyone know how I could turn the first of this into a string/or something usable?</p>