title: PHP Fatal error: Cannot use object of type simple_html_dom as array
body: <p>I am working on web scraping application using <code>simple_html_dom</code>. I need to extract all the images in a web page. The following are the possibilities:</p>
  <ol>
  <li><code>&lt;img&gt;</code> tag images</li>
  <li>if there is a css with the <code>&lt;style&gt;</code> tag in the same page.</li>
  <li>if there is an image with the inline style with <code>&lt;div&gt;</code> or with some other tag.</li>
  </ol>
  <p>I can scrape all the images by using the following code.</p>
  <pre><code>function download_images($html, $page_url , $local_url){
  
      foreach($html-&gt;find('img') as $element) {
          $img_url = $element-&gt;src;
          $img_url = rel2abs($img_url, $page_url);
          $parts   = parse_url($img_url);
          $img_path=  $parts['path'];
          $url_to_be_change = $GLOBALS['website_server_root'].$img_path;
          download_file($img_url, $GLOBALS['website_local_root'].$img_path);  
          $element-&gt;src=$url_to_be_change;            
      }
  
      $css_inline = $html-&gt;find(&quot;style&quot;);
  
      $matches = array();
      preg_match_all( &quot;/url\((.*?)\)/&quot;, $css_inline, $matches, PREG_SET_ORDER );
      foreach ( $matches as $match )    {
          $img_url = trim( $match[1], &quot;\&quot;'&quot; );
          $img_url = rel2abs($img_url, $page_url);
          $parts   = parse_url($img_url);
          $img_path=  $parts['path'];
          $url_to_be_change = $GLOBALS['website_server_root'].$img_path  ;
          download_file($img_url , $GLOBALS['website_local_root'].$img_path); 
          $html = str_replace($img_url , $url_to_be_change , $html );
      }
  
      return $html;
  }
  
  $html = download_images($html , $page_url , $dir); // working fine
  $html = str_get_html ($html);
  $html-&gt;save($dir. &quot;/&quot; . $ff);    
  </code></pre>
  <p>Please note that, I am modifying the HTML too after image downloading.</p>
  <p>downloading is working fine. but when i am trying to save the HTML, then its giving the following error:</p>
  <blockquote>
  <p>PHP Fatal error:  Cannot use object of type simple_html_dom as array</p>
  </blockquote>
  <p>Important: its working perfectly fine, if I am not using <code>str_replace</code> and second loop.</p>
  <blockquote>
  <p>Fatal error:  Cannot use object of type simple_html_dom as array in /var/www/html/app/framework/cache/includes/simple_html_dom.php on line 1167</p>
  </blockquote>