I'm using this code (thank you Lawrence) to parse HTML table:
<?php
$html = file_get_contents('http://www.example.com');
$dom = new DOMDocument();
@$dom->loadHTML($html);
//TUE 1 1 4.37 6.39 1.08 5.35 9.18 6.00 1.30 6.30 7.42 9.40
echo '
<table>
<tr>';
foreach($dom->getElementsByTagName('table') as $table) {
echo innerHTML($table->getElementsByTagName('tr')->item(9));
}
echo '
</tr>
</table>';
function innerHTML($current){
$ret = "";
$nodes = @$current->childNodes;
if(!empty($nodes)){
foreach($nodes as $v){
$tmp = new DOMDocument();
$tmp->appendChild($tmp->importNode($v, true));
$ret .= $tmp->saveHTML();
}
return $ret;
}
return;
}
?>
The problem is that it outputs original HTML code, so how can I output plain text?
I have tried these changes, but it didn't work:
return $ret->textContent;
return $ret->nodeValue;
return $ret->plaintext;
echo innerHTML($table->getElementsByTagName('tr')->item(9)->textContent);
echo innerHTML($table->getElementsByTagName('tr')->item(9)->nodeValue);
echo innerHTML($table->getElementsByTagName('tr')->item(9)->plaintext);