【问题标题】:how to fix in use of file_get_html如何修复使用 file_get_html
【发布时间】:2019-09-10 22:26:33
【问题描述】:

我使用file_get_html 的这段代码从 php 中的 html 文件中回显一个 tah。

但是在本地运行我的代码后出现错误。

错误:

致命错误:未捕获的错误:调用 C:\xampp\htdocs\2\index.php:2 中未定义的函数 file_get_html() 堆栈跟踪:#0 {main} 在 C:\xampp\htdocs\2\ 中抛出第 2 行的 index.php

php 代码:

<?php
$html = file_get_html('http://example.com/');
        
// Find all images 
foreach($html->find('img') as $element);
    echo $element->src . '<br>';
    
// Find all links 
foreach($html->find('a') as $element);
    echo $element->href . '<br>';
?>

这是更改后的错误:

警告:file_get_contents():流不支持在 C:\xampp\htdocs\2\simple_html_dom.php 中的第 75 行查找

警告:file_get_contents():未能在第 75 行 C:\xampp\htdocs\2\simple_html_dom.php 中的流中定位 -1

致命错误:未捕获的错误:在 C:\xampp\htdocs\2\index.php:7 中调用布尔值上的成员函数 find() 堆栈跟踪:#0 {main} 在 C:\xampp\htdocs 中抛出\2\index.php 在第 7 行

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    我认为您缺少一些步骤。应该看起来像这样:

    // Include the library
    include('simple_html_dom.php');
    
    // Retrieve the DOM from a given URL
    $html = file_get_html('http://example.com/');
    
    // Find all "A" tags and print their HREFs
    foreach($html->find('a') as $e) 
        echo $e->href . '<br>';
    

    这是图书馆的链接,希望它有效... https://tenet.dl.sourceforge.net/project/simplehtmldom/simplehtmldom/1.8.1/simplehtmldom_1_8_1.zip

    【讨论】:

      猜你喜欢
      • 2013-02-04
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      • 2014-06-05
      • 2021-01-15
      • 2019-10-27
      • 2016-10-14
      相关资源
      最近更新 更多