This will do it, it just grabs the third table, iterates over the rows and checks for B and D in the second and fourth columns. If found, it prints each column value, and then stops the loop.
$dom = new DOMDocument(); $dom->loadHTML(.....); // get the third table $thirdTable = $dom->getElementsByTagName('table')->item(2); // iterate over each row in the table foreach($thirdTable->getElementsByTagName('tr') as $tr) { $tds = $tr->getElementsByTagName('td'); // get the columns in this row if($tds->length >= 4) { // check if B and D are found in column 2 and 4 if(trim($tds->item(1)->nodeValue) == 'B' && trim($tds->item(3)->nodeValue) == 'D') { // found B and D in the second and fourth columns // echo out each column value echo $tds->item(0)->nodeValue; // A echo $tds->item(1)->nodeValue; // B echo $tds->item(2)->nodeValue; // C echo $tds->item(3)->nodeValue; // D break; // don't check any further rows } } }
source share