i have table like
<html>
<body>
<table id="data" class="outer">
<tr><td>Date</td><td>12-09-12</td></tr>
<tr><td>Price</td><td>15.00</td></tr>
<tr><td>Count</td><td>67</td></tr>
</table>
</body>
</html>
i have to parse this to give out put for more than 100
but i am unable to get how value for “Date” “12-09-12” can be replaced with new value from database value.
please give me a small example
$html = new simple_html_dom();
$html->load_file($page);
$items = $html->find('Date');
`
$s = '<html>
<body>
<table id="data" class="outer">
<tr><td>Date</td><td>12-09-12</td></tr>
<tr><td>Price</td><td>15.00</td></tr>
<tr><td>Count</td><td>67</td></tr>
</table>
</body>
</html>';
$document = new DOMDocument();
$document->loadHTML($s);
$oElement = $document->getElementById('data');
$tds = $oElement->getElementsByTagName('td');
if( 'td' == strtolower($tds->item(0)->tagName) AND 'date' == strtolower($tds->item(0)->nodeValue) )
{
echo 'Old value: ' . $tds->item(1)->nodeValue;
echo '<hr/>';
$tds->item(1)->nodeValue = '13-08-11';
echo $document->saveHTML(); //output modified HTML
}
?>
`can anyone help me ?
Using Simple HTML DOM package it can be done like this.
table#data tr tdselector finds all TD tags inside TR tags inside TABLE withid="data".$html->find('table#data tr td', 1)returns second of found elements (index is 1).