HTML简单DOM结果到HTML表

时间:2016-06-03 05:18:55

标签: php html dom html-table simpledom

我有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>

1 个答案:

答案 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>