Possible Duplicate:
Regular expression for grabbing the href attribute of an A element
This displays the what is between the a
tag, but I would like a way to get the href
contents as well.
Is there a way to do that using the domDocument?
$html = file_get_contents($uri);
$html = utf8_decode($html);
/*** a new dom object ***/
$dom = new domDocument;
/*** load the html into the object ***/
@$dom->loadHTML($html);
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
/*** the table by its tag name ***/
$tables = $dom->getElementsByTagName('table');
/*** get all rows from the table ***/
$rows = $tables->item(0)->getElementsByTagName('tr');
/*** loop over the table rows ***/
foreach ($rows as $row)
{
$a = $row->getElementsByTagName('a');
/*** echo the values ***/
echo $a->item(0)->nodeValue.'<br />';
echo '<hr />';
}