提问人:acoder 提问时间:12/16/2018 更新时间:12/16/2018 访问量:1672
本地服务器上的 PHP 简单 HTML DOM 解析器
PHP Simple HTML DOM Parser on a local server
问:
是什么原因导致“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} 抛入.....在线。。。。。
答:
1赞
u_mulder
12/16/2018
#1
阅读手册(始终是一个选项)说该函数是在load
simple 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_dom
file_get_html
str_get_html
评论
file_get_html
file_get_contents
load
$html