1

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!

  • Why not just use DOMDocument like everyone else? http://php.net/manual/en/class.domdocument.php – delboy1978uk Oct 23 '18 at 08:52
  • @UdhavSarvaiya sorry mate, but I didn't get what you mean by `file_get_contents.php`, `simple_html_dom.php` so, which folder these are in Laravel? or do I need to install these, because about simple_dom installation there is no record for this. –  Oct 23 '18 at 12:12

2 Answers2

1

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);
firefly
  • 876
  • 2
  • 15
  • 42
0

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.

Spudley
  • 166,037
  • 39
  • 233
  • 307
  • load the file means, use DOMdocument and after that pass the URL to simple_dom? –  Oct 23 '18 at 12:14