私はテーブルのtrを取得していて、ループ内ですべてのtdフィールドのテキストを取得したいのですが、ここを見てください:
<?
$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();
?>
なぜNULLになるのですか?
今私が持っています:
$lines = $xpath->query("//table[@id='cab_table'] //tr");
foreach($lines as $line) {
$tds = $xpath->query('//td', $line);
$count = $tds->length;
for($i=0; $i<$count; $i++){
echo $tds->item($i)->nodeValue.'<br>';
//echo $i.'<br>';
}
}
しかし、私はループで各trの次を作りたいです$result[0] = td[0]; $result[1] = td[1]; $result[2] = td[2];
私にアドバイスできますか?
foreach($lines as $line) {
for($j=0; $j<=3; $j++) {
$tds_{$j} = $xpath->query('//td['.$j.']', $line);
$tds_{$j} = $xpath->query('//td['.$j.']', $line);
$tds_{$j} = $xpath->query('//td['.$j.']', $line);
$count = $tds_{$j}->length;
for($i=0; $i<$count; $i++){
$this->result['number'][] = $tds_{$j}->item($i)->nodeValue;
$this->result['volume'][] = $tds_{$j}->item($i)->nodeValue;
$this->result['code'][] = $tds_{$j}->item($i)->nodeValue;
$this->result['start_date'][] = $startDate;
$this->result['end_date'][] = $endDate;
}
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加