I need to display a table from an external website on my own website. The reason is that the content of this table changes daily and I don't want to change it manually on my website.
This is my approach so far:
<!-- This is the exemplary HTML code of the external website -->
<html>
<head>...</head>
<body>
<!-- some content -->
<div id="table-id">
<table>
<!-- table content -->
</table>
</div>
<!-- some other content -->
</body>
</html>
<?php
$homepage = file_get_contents('http://www.my-source-website.com');
$homepage = htmlentities($homepage);
libxml_use_internal_errors(true);
$doc = new DOMDocument("1.0", "utf-8");
$doc->validateOnParse = true;
$doc->loadHTML($homepage);
$selector = new DOMXPath($doc);
$result = $selector->query('//div[@id="table-id"]');
foreach($result as $node) {
echo $node->textContent;
}
?>
This code seems to be not correct. I'm getting a kind of empty result. Am I on the right way to solve my issue?
I know I could solved this issue with an regular expression, but I've read that this wouldn't be a flexible good solution.
</div>