且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

简单的 html dom 解析器表到数组

更新时间:2023-02-26 10:37:34

也许可以尝试将每一行放入一个数组中,然后将每个单元格放入另一个数组中.希望这能满足您的需求.

Maybe try putting each row into an array and then each cell into another array. Hopefully, that will do what you want.

require('simple_html_dom.php');
$html = file_get_html('http://flightplan.romatsa.ro/init/fpl/flightslr/LRCL/');

$table = $html->find('table', 3);
$rowData = array();

foreach($table->find('tr') as $row) {
    // initialize array to store the cell data from each row
    $flight = array();
    foreach($row->find('td') as $cell) {
        // push the cell's text to the array
        $flight[] = $cell->plaintext;
    }
    $rowData[] = $flight;
}

echo '<table>';
foreach ($rowData as $row => $tr) {
    echo '<tr>'; 
    foreach ($tr as $td)
        echo '<td>' . $td .'</td>';
    echo '</tr>';
}
echo '</table>';

注意:此解决方案需要 simple_html_dom.php 库.从这里获取!