title: Displaying all images from a WordPress post
body: <p>I have this piece of code I found on some blog, that's supposed to display all images from a WordPress post. </p>
  
  <pre><code>function getImage() {
      global $more;
      $more = 1;
      $link = get_permalink();
      $content = get_the_content();
      $count = substr_count($content, '&lt;img');
      $start = 0;
      for($i=1;$i&lt;=$count;$i++) {
          $imgBeg = strpos($content, '&lt;img', $start);
          $post = substr($content, $imgBeg);
          $imgEnd = strpos($post, '&gt;');
          $postOutput = substr($post, 0, $imgEnd+1);
          $postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);;
          if(stristr($postOutput,'&lt;img')) { echo $postOutput; }
          $start=$imgEnd+1;
      }
      $more = 0;
  }
  </code></pre>
  
  <p>What happens though... it displays first and second image correctly, then loops the second image instead of 3rd 4th etc. It grabs the number of images okay, but instead of displaying 1st, 2nd, 3rd, 4th image, it displays 1st, 2nd, 2nd, 2nd...</p>
  
  <p>Could anyone look at this snippet and maybe come up with an idea why this happens? I know the code is rather sloppy, but I just found it on some blog, being a PHP newbie and all :)</p>
  
  <p>All help appreciated, thanks in advance!</p>