gpt4 book ai didi

php - 如何使用 file_get_contents 或 file_get_html?

转载 作者:可可西里 更新时间:2023-10-31 22:18:52 29 4
gpt4 key购买 nike

我已经阅读了很多关于这里的问题,我不确定我是否应该为此使用 file_get_contentsfile_get_html

我想做的就是使用 PHP 在我的网站上显示此页面中的两个表:http://www.statmyweb.com/recently-analyzed/

当然,我知道如何获取他们的完整页面并将其显示在我的网站上,但我不知道如何在不获取页眉/页脚的情况下只拉出这两个表格。

最佳答案

您需要 file_get_html,因为 file_get_contents 会将响应主体加载到字符串中,而 file_get_html 会将其加载到 simple-html-dom 中。

$dom = file_get_html($url);
$tables = $dom->find('table');
echo $tables[0];
echo $tables[1];

或者,您可以将 file_get_contentsstr_get_html 一起使用:

$dom = str_get_html(file_get_contents($url));

但这很愚蠢。

关于php - 如何使用 file_get_contents 或 file_get_html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14962359/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com