Php 简单\u Dom错误:文件\u获取\u内容():流不支持在Laravel中查找
我得到一个错误如下 文件\u获取\u内容():流不支持查找 我是由一位作曲家安装simple_dom的:Php 简单\u Dom错误:文件\u获取\u内容():流不支持在Laravel中查找,php,laravel,simpledom,Php,Laravel,Simpledom,我得到一个错误如下 文件\u获取\u内容():流不支持查找 我是由一位作曲家安装simple_dom的: composer require sunra/php-simple-html-dom-parser 也用了这个: use Sunra\PhpSimple\HtmlDomParser; 这是我的代码: $weblink = "http://www.sumitomo-rd-mansion.jp/kansai/"; function fetch_sumitomo_links($webl
composer require sunra/php-simple-html-dom-parser
也用了这个:
use Sunra\PhpSimple\HtmlDomParser;
这是我的代码:
$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);
$weblink=”http://www.sumitomo-rd-mansion.jp/kansai/";
函数获取住友链接($weblink)
{
$htmldoc=htmlcomparser::file\u get\u html($weblink);
foreach($htmldoc->find(.areaBox a)作为$a){
$links[]=$a->href.
;
}
返回$links;
}
$items=fetch_sumitomo_链接($weblink);
打印(项目);
但我有个错误。有什么想法吗?
谢谢你的帮助 答案在错误消息中。用于读取数据的输入源不支持查找 更具体地说,
$htmldoc->find()
方法试图直接读取文件以搜索它想要的内容。但是,因为您直接通过http读取文件,而http不支持此功能
您可以选择先加载文件,这样
htmlcomparser
就不必从磁盘进行搜索,或者如果需要从磁盘进行搜索,那么它至少可以从支持搜索的本地数据源进行读取。这是问题修复程序:
$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);
$url='1!'http://www.sumitomo-rd-mansion.jp/kansai/';
函数获取住友链接($url)
{
$htmldoc=HTMLDOPARSER::file_get_html($url,false,null,0);
foreach($htmldoc->find(.areaBox a)作为$a){
$links[]=$a->href.
;
}
返回$links;
}
$items=fetch_sumitomo_链接($url);
打印(项目);
为什么不像其他人一样使用DOMDocument@Udhavasrvaya抱歉,伙计,但我不明白你所说的file\u get\u contents.php
,simple\u html\u dom.php
那么,它们在Laravel的哪个文件夹中?或者我需要安装这些,因为关于simple_dom安装,没有记录。加载文件意味着,使用DOMdocument,然后将URL传递给simple_dom?