title: How do I get the h1 inside a loop in simple html dom?
body: <p>
  
  <p>How do I get the h1 inside a loop in simple html dom?
  This is the code that I'm using to fetch images and save them in a folder.
  It works fine.</p>
  
  <p>But I don't have any idea on how to save h1 as file name</p>
  
  <pre><code>include("simple_html_dom.php");
  $files = file_get_contents("http://picjumbo.com/page/2/");
  $html = new simple_html_dom();  
  $html-&gt;load($files);  
  
  
  //Get all the item-wrap divs
  foreach($html-&gt;find('div[class=item_wrap]') as $item_wrap){
      //fetch each image and save it
      foreach($item_wrap-&gt;find('img[class=image]') as $img){  
          $img_src = explode('/',$img-&gt;src);
          $img_src  = explode('-',$img_src[5]);
          $img = $img_src[0];
          $url = 'http://picjumbo.com/wp-content/themes/picjumbofree/run.php?download&amp;d='.$img.'.jpg';
          copy($url, 'images/'.$img.'.jpg');
      }
  }
  </code></pre>
  
  <p>I tried this but it is not working.I can't get my head around it</p>
  
  <pre><code>foreach($html-&gt;find('div[class=item_wrap]') as $item_wrap){
      foreach($item_wrap-&gt;find('img[class=image]') as $img){  
          $img_src = explode('/',$img-&gt;src);
          $img_src  = explode('-',$img_src[5]);
          $img = $img_src[0];
  
          //this throws an error (I know a foreach is required but how do I save h1 as file name with it?)
          $h1 = $item_wrap-&gt;find('h1')-&gt;plaintext;
  
          $url = 'http://picjumbo.com/wp-content/themes/picjumbofree/run.php?download&amp;d='.$h1.'.jpg';
          copy($url, 'images/'.$img.'.jpg');
      }
  }
  </code></pre>
  
  <p>You get the idea right?I just want to save the image as h1.
  Need your help!!!</p>