file_get_contents(): stream does not support seeking / When was PHP behavior about this changed?

re1 picture re1 · Mar 9, 2017 · Viewed 36.5k times · Source

When was PHP behavior about this changed?

From which PHP version is it?


Warning: file_get_contents(): stream does not support seeking in /simple_html_dom.php

Warning: file_get_contents(): Failed to seek to position -1 in the stream in /simple_html_dom.php


include('parser/simple_html_dom.php');
$url = "https://en.wikipedia.org/wiki/Stack_Overflow";
$html = file_get_html($url);
if ($html !== false) {
  foreach($html->find('div#mw-content-text') as $item){
    $item->plaintext;
  }
}

Answer

Rmj86 picture Rmj86 · May 23, 2017

I had the same issue on my page when I moved it from one system to another, I was able to change the simple_html_dom.php file by removing the offset reference (didn't cause any further problems for me).

On line 75 of simple_html_dom.php:

$contents = file_get_contents($url, $use_include_path, $context, $offset);

I removed the reference to $offset:

$contents = file_get_contents($url, $use_include_path, $context);

No my page works fine. Not taking liability for anything else it breaks! :)