title: how to limit foreach loop to four loops
body: <p>Is it possible to limit this loop ..just to four loops?</p>
  
  <p>I got this source on another post and it's working but i just need to limit the loop </p>
  
  <pre><code>        $scraper = new DOMScraper();
         $scraper-&gt;setSite('http://anywebsite.com/testig12.aspx')-&gt;setSource();
          Class DOMScraper extends DOMDocument{
          public $site;
          private $source;
          private $dom;
  
      function __construct(){
      libxml_use_internal_errors(true);
      $this-&gt;preserveWhiteSpace = false;
      $this-&gt;strictErrorChecking = false;
  }
  
  function setSite($site){
      $this-&gt;site = $site;
      return $this;
  }
  
   function setSource(){
       if(empty($this-&gt;site))return 'Error: Missing $this-&gt;site, 
       use  setSite() first';
       $this-&gt;source = $this-&gt;get_data($this-&gt;site);
       return $this;
   }
  
   function getInnerHTML($tag, $id=null, $nodeValue = false){
      if(empty($this-&gt;site))return 'Error: Missing $this-&gt;source, 
      use setSource() first';
      $this-&gt;loadHTML($this-&gt;source);
      $tmp = $this-&gt;getElementsByTagName($tag);
      $ret = null;
      foreach ($tmp as $v){ 
          if($id !== null){
              $attr = explode('=',$id);
              if($v-&gt;getAttribute($attr[0])==$attr[1]){
                  if($nodeValue == true){
                      $ret .= trim($v-&gt;nodeValue);
                  }else{
                      $ret .= $this-&gt;innerHTML($v);
                  }
              }
          }else{
              if($nodeValue == true){
                  $ret .= trim($v-&gt;nodeValue);
              }else{
                  $ret .= $this-&gt;innerHTML($v);
              }
          }
      }
      return $ret;
   }
  
   function innerHTML($dom){
      $ret = "";
      $nodes = $dom-&gt;childNodes;
      foreach($nodes as $v){
          $tmp = new DOMDocument();
          $tmp-&gt;appendChild($tmp-&gt;importNode($v, true));
          $ret .= trim($tmp-&gt;saveHTML());
      }
      return $ret;
   }
  
    function get_data($url){
      if(function_exists('curl_init')){
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
          curl_setopt($ch, CURLOPT_TIMEOUT, 5);
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          $data = curl_exec($ch);
          curl_close($ch);
          return $data;
      }else{
          return file_get_contents($url);
      }
  }
    }
    ?&gt;
  </code></pre>
  
  <p>then here is where i want to limit the display becouse not it scrap all the data from that site like 2000 records.. i want to load only latest 4 </p>
  
  <pre><code> &lt;?php echo '&lt;div&gt;'.$scraper-&gt;getInnerHTML('div','id=LeftDiv12').'&lt;/div&gt;'; ?&gt;
  </code></pre>
  
  <p>Thank you</p>