我正在尝试在我的本地主机上学习 HTML DOM 解析。但我一开始就崩溃了。
1) 我做了一个新项目
2) 我已经从 simplehtmldom.sourceforge.net 下载了文件
3) 我已将此代码放入我的 HTML 项目中
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
// put your code here
$html = file_get_html('http://www.google.com/');
?>
</body>
</html>
4) 当我运行脚本时出现这个错误:
fatal error :未捕获错误:调用 C:\xampp\htdocs\PhpProject1\index.php:15 中的未定义函数 file_get_html() 堆栈跟踪:#0 {main} thrown in C:\xampp\htdocs\PhpProject1\第 15 行的 index.php
我是不是误会了什么?
最佳答案
我认为 PHP DOM 解析器库不再支持 PHP 最新版本,因此,您需要为此使用 cURL 它会对您有所帮助。
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.google.co.in");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
print $result;
?>
试试这个..!
关于php - 简单的 HTML DOM 解析不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45392279/