How to use file_get_contents or file_get_html?

I read a few questions here, and I'm not sure if I should use file_get_contents or file_get_html for this.

All I'm trying to do is use PHP to display two tables from this page on my website: http://www.statmyweb.com/recently-analyzed/

I know how to get a full page and show it on my site, but I can’t understand how I can just pull out these two tables without getting a header / footer.

+7
source share
3 answers

You cannot specify in file_get_contents() just to retrieve tables.

You need to get the return value of file_get_contents() using:

 $result = file_get_contents("urlHere"); 

Then parse the $result variable and extract the necessary information for output.

+1
source

You want file_get_html because file_get_contents load the response body into a string, but file_get_html load it in simple-html-dom.

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

Alternatively, you can use file_get_contents along with str_get_html :

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

But that would be stupid.

+24
source

Download the full site content for file_get_contents() , then apply preg_match to the content you have with <table> and </table> . This will bring you all the content under the table tags. To show this on your web page, just put <table> , then echo your consistent content and </table> at the end.

0
source

All Articles