php - 简单的 HTML DOM 解析不起作用

标签 php html parsing sourceforge

我正在尝试在我的本地主机上学习 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/

相关文章:

php - 如何为 php-jwt 生成 key 对?

php - 使用 PHP 向 IOS 设备发送通知

php - MySQL 日期格式

javascript - Bootstrap 导航栏不显示 CSS

angular - 绑定(bind)表达式不能包含链式表达式 (Angular 8)

json - 如何在以下代码中访问 __nssingleobjectarrayi 的值

PHP preg_replace 非字母数字导致数据库插入失败

javascript - 加载网页的无 JavaScript 版本

html - 在 html 页面中使用 Ajax 加载 Google Chart Api

python - 使用正则表达式获取错误数据