I am trying to figure out how to parse a website to get the links out of a table. In my particular case there are two tables, but I only want the links from the second table (Link5 & Link6). Here is the HTML I am trying to parse.

```
<html>
<head>
</head>
<body>
<a href="http://www.example.com/link1.html">Link1</a><br>
<br>
<table>
  <tbody>
    <tr>
      <td><a href="http://www.example.com/link2.html">Link2</a></td>
      <td>dog</td>
      <td>fish</td>
    </tr>
    <tr>
      <td><a href="http://www.example.com/link3.html">Link3</a></td>
      <td>cat</td>
      <td>bird</td>
    </tr>
  </tbody>
</table>
<br>
<a href="http://www.example.com/link4.html">Link4</a><br>
<br>
<table>
  <tbody>
    <tr>
      <td><a href="http://www.example.com/link5.html">Link5</a></td>
      <td>cow</td>
    </tr>
    <tr>
      <td><a href="http://www.example.com/link6.html">Link6</a></td>
      <td>horse</td>
    </tr>
  </tbody>
</table>
<br>
<a href="http://www.example.com/link7.html">Link7</a><br>
</body>
</html>

```

I have read that DOM is a good way to parse data from the web, so here is the code I have been working on.

```
<?php
$link = array();

//new dom object
$dom = new DOMDocument();

//load the html
$html = $dom->loadHTMLFile('http://www.example.com');

//discard white space 
$dom->preserveWhiteSpace = false; 

//get the table by its tag name
$tables = $dom->getElementsByTagName('table');   

$rows = $tables->item(1)->getElementsByTagName('tr');

$i = 0;

//loop over the table rows
foreach ($rows as $row) 
{ 
    $links = $row->getElementsByTagName('a');

    //put node value into an array
    $link[] = $links->item(0)->nodeValue;

    // echo the values
    echo $link[$i] . '<br />';

    $i++;
} 

?>

```

This code gives the following output:
Link5
Link6

But what I would like to achieve is:
<http://www.example.com/link5.html>
http://www.example.com/link6.html

Any help would be greatly appreciated.