我已经阅读了很多关于这里的问题,我不确定我是否应该为此使用 file_get_contents
或 file_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_contents
与 str_get_html
一起使用:
$dom = str_get_html(file_get_contents($url));
但这很愚蠢。
关于php - 如何使用 file_get_contents 或 file_get_html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14962359/