Simple html dom parser table to array

前端 未结 1 1974
花落未央
花落未央 2020-12-10 06:18

I\'m trying to parse the arrivals table from here [1] and put in into an array to be able to format it and put it into a table.

I did some research here and there, I

相关标签:
1条回答
  • 2020-12-10 06:37

    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>';
    

    Note: this solution requires the simple_html_dom.php library. Get it here!

    0 讨论(0)
提交回复
热议问题