我有HTML简单DOM的问题。我需要从两个列的解析到HTML表格中获得结果。
我有以下代码:
<table>
<?php
$html = '<td class="colEvent">
<span class="zapas" data-m="2423050">Wawrinka-A.Murray</span>
<span class="datum">03.06. 15:05</span></td>';
$dat = array();
foreach($html->find('span[class=datum]') as $date) {
$dat[] = $date->innertext;
$a = strip_tags($date->innertext, '<br>');
echo "<tr><td>$a</td>";
}
$zap = array();
foreach($html->find('span[class=zapas]') as $match) {
$zap[] = $match->innertext;
$c = strip_tags($match->innertext, '<br>');
echo "<td>$c</td></tr>";
}
?>
</table>
答案 0 :(得分:0)
试试这个:
<table>
<?php
$html = '<td class="colEvent">
<span class="zapas" data-m="2423050">Wawrinka-A.Murray</span>
<span class="datum">03.06. 15:05</span></td>';
$dat = array(); $zap = array();
for($i=0; $i<count($html->find('span[class=datum]')); $i++){
$dat[] = $html->find('span[class=datum]')[$i]->innertext;
$a = strip_tags($html->find('span[class=datum]')[$i]->innertext, '<br>');
echo "<tr><td>".$a."</td>";
$zap[] = $html->find('span[class=zapas]')[$i]->innertext;
$c = strip_tags($html->find('span[class=zapas]')[$i]->innertext, '<br>');
echo "<td>".$c."</td></tr>";
}
?>
</table>