file_get_contents():stream不支持搜索/什么时候PHP行为有关此更改?

re1*_*re1 16 php simple-html-dom

PHP的行为何时发生变化?

从哪个PHP版本?


警告:file_get_contents():stream不支持在/simple_html_dom.php中搜索

警告:file_get_contents():无法在/simple_html_dom.php的流中寻找-1位置


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;
  }
}
Run Code Online (Sandbox Code Playgroud)

小智 96

当我将它从一个系统移动到另一个系统时,我在页面上遇到了同样的问题,我能够simple_html_dom.php通过删除偏移引用来更改文件(不会给我带来任何进一步的问题).

在第75行simple_html_dom.php:

$contents = file_get_contents($url, $use_include_path, $context, $offset);
Run Code Online (Sandbox Code Playgroud)

我删除了对$offset以下内容的引用

$contents = file_get_contents($url, $use_include_path, $context);
Run Code Online (Sandbox Code Playgroud)

没有我的页面工作正常.不对其他任何事情承担责任!:)

  • 简单而又精彩!天才! (3认同)

小智 20

更改

function file_get_html(..., $offset = -1,...)
Run Code Online (Sandbox Code Playgroud)

function file_get_html(..., $offset = 0,...)
Run Code Online (Sandbox Code Playgroud)

在simple_html_dom.php中


Chu*_*utt 14

您无需编辑供应商文件.只需更改您的请求:

$html = HtmlDomParser::file_get_html( "https://www.google.com/");
Run Code Online (Sandbox Code Playgroud)

至:

$html = HtmlDomParser::file_get_html( "https://www.google.com/", false, null, 0 );
Run Code Online (Sandbox Code Playgroud)

问题是当您希望Simple HTML DOM为"0"时,它使用的默认偏移量为"-1".幸运的是,它接受它作为参数,这意味着您可以轻松地更改它而无需更改Simple HTML DOM源.

注意:此兼容性问题已在v1.7 +中修复


le_*_*e_m 3

请参阅file_get_contents():流不支持 PHP 查找

您正在处理远程文件。仅支持本地文件的查找。

在使用之前,您可能需要将文件复制到本地文件系统file_get_html。它应该在本地主机上正常工作。

  • 根据更改日志http://php.net/manual/en/function.file-get-contents.php,关于远程文件的查找没有任何变化。这就是为什么我假设您以前只使用可以进行搜索的本地文件(或者您很幸运,因为根据文档,有时搜索也可能适用于远程文件的小范围)。 (2认同)