Get text td Xpath PHP -


i getting tr of tables , in loop want text of td fields, here:

<?     $lines = $xpath->query("//table[@id='cab_table'] //tr");        var_dump($lines);// give me object(domnodelist)#11 (1) { ["length"]=> int(6) }               for( $i = 0; $i < count($lines); $i++) {                 if($i != 0){                     $tds = $xpath->query('//td', $lines[$i]);                     $result[$i - 1]['number'] = trim($tds->item(0)->nodevalue);                     $result[$i - 1]['volume'] = trim($tds->item(1)->nodevalue);                     $result[$i - 1]['sum'] = trim($tds->item(2)->nodevalue);                 }             }              var_dump($result); //give me null             die(); 

?>

why null?

now have:

$lines = $xpath->query("//table[@id='cab_table'] //tr");               foreach($lines $line) {              $tds = $xpath->query('//td', $line);              $count = $tds->length;                  for($i=0; $i<$count; $i++){                      echo $tds->item($i)->nodevalue.'<br>';                     //echo $i.'<br>';                   }              } 

but want make next each tr @ loop $result[0] = td[0]; $result[1] = td[1]; $result[2] = td[2]; can advise me?

->query() returns domnodelist object. can count()ed , foreach()ed, can't use array are.

$tds = $xpath->query('//td', $lines[$i]);                              ^^^^^^^^^^---incorrect 

try

$lines = $xpath->query("//table[@id='cab_table'] //tr"); foreach($lines $line) {     $tds = $xpath->query('//td', $line);     ... } 

instead.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -