title: Extract image from the content
body: <p>I want to extract images from the_content() and want to display first images from post on index.php and want to display all images on single.php. To do this I apply a filter on the_content():</p>
  
  <pre><code>&lt;?php
  /*****************************************************************************
      Post Summary Filter - Grap Image Thumbnails, Strip Tags, etc
  ******************************************************************************/
  add_filter('the_content', 'filterContentSummary', 0);
  
  function filterContentSummary($content){
      global $post;
  
      if( is_home() || is_category() || is_tag() || is_author() || is_date() || is_search() || is_single ){
          //if NOT single page or "page" page
              $img='';        //default img code
              $final_width = 300;
  
              $content = $post-&gt;post_content;
  
              //search for first image in article
              preg_match('/&lt;img[^&gt;]*&gt;/i',$content,$matches);
  
              //image found, process it
              if($matches){
                  preg_match('/src="[^"]*"/i',$matches[0],$src);
                  preg_match('/width="(\d*)[^"]*"/i',$matches[0],$width);
  
                  if($width[1] &lt; $final_width){
                      $final_width = $width[1];
                  }
  
  
              }
  
              //prepare text
              if(!empty($post-&gt;post_excerpt)){
                  $content = $post-&gt;post_excerpt;
              }else{
                  //strip shortcodes, tags
                  $content = preg_replace('/\[\/*[^\]]*\]/i', '', $content);  //cont is ready
                  $content = preg_replace('/&lt;[^&gt;]*&gt;/i', '', $content);    //cont is ready
                  $content = substr($content,0,500);
                  $content = explode(". ", $content);
  
                  array_pop($content);
                  $content = implode(". ", $content) . "";
              }
  
              if($content=="."){
                  $content = $post-&gt;post_content;
              }
              //prepare final content
              $content =  "&lt;p&gt;". $content ."&lt;/p&gt;";
  
              //Adding Read more link
              $content .= "&lt;p align='right' class='seemore'&gt;&lt;a href=".  get_permalink() . "&gt;&lt;/a&gt;&lt;/p&gt;";
      }
      // Make sure to return the content
      return $content;
  }
  ?&gt;
  </code></pre>
  
  <p>On index.php using regular expressions I find the first image from the post and display it: </p>
  
  <pre><code>&lt;?php while (have_posts()) : the_post();
                              $content = $post-&gt;post_content;
                              preg_match_all('/(&lt;img.*src="(.*)"[^&gt;]*&gt;)/iU',$content,$matches);
                          ?&gt;
  </code></pre>
  
  <p>Now <code>$matches</code> have all the images:</p>
  
  <pre><code>&lt;div class="content-img"&gt;&lt;img src="&lt;?php echo $matches[2][0];?&gt;"/&gt;&lt;/div&gt;
  </code></pre>
  
  <p>...used to display first image on a post.</p>
  
  <p>But how I can display all images on single.php ?</p>