本地服务器上的 PHP 简单 HTML DOM 解析器

PHP Simple HTML DOM Parser on a local server

提问人:acoder 提问时间:12/16/2018 更新时间:12/16/2018 访问量:1672

问:

是什么原因导致“PHP Simple HTML DOM Parser”在本地服务器上无法正常工作。会不会是配置问题?

PHP 版本 7.2.12

<?php

include('simple_html_dom.php');

$html = file_get_contents('http://www.google.com/');
$html->load($html);

?>

给出以下错误:

致命错误:未捕获的错误:调用成员函数 load() on 字符串.....堆栈跟踪:#0 {main} 抛入.....在线。。。。。

php 解析 simple-html-dom

评论

1赞 Rohit Rasela 12/16/2018
try 而不是file_get_htmlfile_get_contents
0赞 Mohammad 12/16/2018
您尝试调用该方法是字符串load$html

答:

1赞 u_mulder 12/16/2018 #1

阅读手册(始终是一个选项)说该函数是在loadsimple html dom

// Create a DOM object
$html = new simple_html_dom();

// Load HTML from a string
$html->load('<html><body>Hello!</body></html>');

因此,您的代码应重写为:

$html = new simple_html_dom();
$html->load(file_get_contents('http://www.google.com/'));

顺便说一句 - 还有更多方法可以加载内容,例如 .simple_html_domfile_get_htmlstr_get_html