【问题标题】:Failed to seek to position -1 in the stream未能在流中寻找位置 -1
【发布时间】:2017-08-19 10:36:06
【问题描述】:

我正在使用 SimpleHTMLDOM 解析器从其他站点获取数据。这在 PHP 7.0 上运行良好。由于我升级到 PHP 7.1.3,我从 file_get_contents 得到以下错误代码:

警告:file_get_contents():流不支持搜索 /..../test/scripts/simple_html_dom.php 上线 75 警告:file_get_contents():未能在 流入 /..../test/scripts/simple_html_dom.php 上线 75

我做了什么

我降级到 PHP 7,它像以前一样工作,没有任何问题。接下来,我查看了解析器的代码。但我没有发现任何异常:

function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
{
    // We DO force the tags to be terminated.
    $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
    // For sourceforge users: uncomment the next line and comment the retreive_url_contents line 2 lines down if it is not already done.
    $contents = file_get_contents($url, $use_include_path, $context, $offset);
    // Paperg - use our own mechanism for getting the contents as we want to control the timeout.
    //$contents = retrieve_url_contents($url);
    if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)
    {
        return false;
    }
    // The second parameter can force the selectors to all be lowercase.
    $dom->load($contents, $lowercase, $stripRN);
    return $dom;
}

我使用的解析器可以在这里找到:http://simplehtmldom.sourceforge.net/

【问题讨论】:

    标签: php parsing dom


    【解决方案1】:

    我遇到了同样的问题。

    PHP 函数 'file_get_contents' 在 PHP 7.1 中发生了变化(添加了对负偏移的支持),因此 Simple HTML5 Dom Parser 中默认使用的 $offset 的 '-1' 值对 PHP>=7.1 无效。你必须把它归零。

    我注意到几天前已经修复了这个错误,所以这个问题应该不会出现在最新版本中(https://sourceforge.net/p/simplehtmldom/repository/ci/3ab5ee865e460c56859f5a80d74727335f4516de/

    【讨论】:

      猜你喜欢
      • 2018-01-31
      • 1970-01-01
      • 2011-11-04
      • 1970-01-01
      • 2019-08-17
      • 1970-01-01
      • 2015-11-06
      • 2014-04-13
      • 2012-03-30
      相关资源
      最近更新 更多