Reputation:
I'm getting a error as below.
file_get_contents(): stream does not support seeking
I installed simple_dom by a composer:
composer require sunra/php-simple-html-dom-parser
and used this too:
use Sunra\PhpSimple\HtmlDomParser;
This is my code:
$weblink = "http://www.sumitomo-rd-mansion.jp/kansai/";
function fetch_sumitomo_links($weblink)
{
$htmldoc = HtmlDomParser::file_get_html($weblink);
foreach ($htmldoc->find(".areaBox a") as $a) {
$links[] = $a->href . '<br>';
}
return $links;
}
$items = fetch_sumitomo_links($weblink);
print_r($items);
But I'm getting an error. Any idea? Thanks for helping!
Upvotes: 1
Views: 1317
Reputation: 906
This is the problem fixer:
$url = 'http://www.sumitomo-rd-mansion.jp/kansai/';
function fetch_sumitomo_links($url)
{
$htmldoc = HtmlDomParser::file_get_html($url, false, null, 0 );
foreach ($htmldoc->find(".areaBox a") as $a) {
$links[] = $a->href . '<br>';
}
return $links;
}
$items = fetch_sumitomo_links($url);
print_r($items);
Upvotes: 1
Reputation: 168655
The answer is in the error message. The input source that you are using to read the data does not support seeking.
More specifically, $htmldoc->find()
method is attempting to read directly into the file to search for what it wants. But because you're reading the file directly over http, which doesn't support this.
Your options are to load the file first so that HtmlDomParser
doesn't have to seek from disk or if you need to seek from disk, so it can at least read from a local data source that does support seeking.
Upvotes: 0