How can I copy two tables from someones website to my website? WordPress

0 Votes

I’m attempting to copy two tables from a specific website address and mimic them onto my website, but I’m unsure how to go about it.

I’ve looked into Simple-HTML-Dom, and I actually got it to work locally on my machine – to a certain extent. Although I have a couple of problems with this approach.

  1. Although I got it to work, it wasn’t perfect. I also dragged over some random text, and I copied across 5 tables – instead of the intended 2.

  2. I would rather use a different method – without using 3rd party scripts?

The tables that I’m attempting to copy can be located here:

I only want the tables containing 2017 and 2016 data (with the headings).

Rates for 2017

Table Headings

Table Contents

Rates for 2016

Table Headings

Table Contents

This would be for my WordPress website.
I don’t know if something could be programmed in PHP to achieve this, or another library that WordPress natively supports without the use of SQL / 3rd party scripts or anything like that.

Thank You



Ok, so I’ve been playing around and trying to debug the code, and I’m almost there!!

I’ve managed to copy over the first table only (second table will be easy).

The final part is trying to add classes to the createElements line? Is that possible??

Here’s my almost finished code.

<h1 class="roeheader">Monthly Industrial Euro Rate:</h1>

$url = "";
$html = file_get_contents($url);
$doc = new DOMDocument();
$result = new DOMDocument();
$result->formatOutput = true;
$table = $result->appendChild($result->createElement("table"));
$thead = $table->appendChild($result->createElement("thead"));
$tbody = $table->appendChild($result->createElement("tbody"));

$xpath = new DOMXPath($doc);

$newRow = $thead->appendChild($result->createElement("tr"));

foreach($xpath->query("//table[1]/thead/tr/th[position()>0]") as $header)
$newRow->appendChild($result->createElement("th", trim($header->nodeValue)));

foreach($xpath->query("//table[1]/tbody/tr") as $row)
$newRow = $tbody->appendChild($result->createElement("tr"));

foreach($xpath->query("./td[position()>0 and position()<5]", $row) as $cell) 
$newRow->appendChild($result->createElement("td", trim($cell->nodeValue)));


echo $result->saveXML($result->documentElement);

I’m trying to change this line:

$newRow->appendChild($result->createElement("td", trim($cell->nodeValue)));

To this:

$newRow->appendChild($result->createElement("td class"roe"", trim($cell->nodeValue)));

But it’s not working?? The page just refuses to load? I guess it’s because of the double quotation.




  1. + -

    Now you can inspect the tables and see the html and css behind them and copy those to your website to make them exactly the same. A good WordPress plugin for making tables is Please let me know if you have further information.

Please signup or login to answer this question.