phplaravelsimpledom

Simple_Dom Error: file_get_contents(): stream does not support seeking in Laravel


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!


Solution

  • 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);