2014-05-07 8 views
6

Sto cercando di analizzare la tabella degli arrivi da qui [1] e inserirla in una matrice per poterla formattare e metterla in una tabella.Semplice tabella di pars del dom per array

Ho fatto qualche ricerca qua e là, ho un po 'di codice da altre domande, ma non riesco a far apparire la matrice e il tavolo come vorrei.

Chiunque può darmi una mano?

<?php 
require('simple_html_dom.php'); 
$html = file_get_html('http://flightplan.romatsa.ro/init/fpl/flightslr/LRCL/'); 
$table = $html->find('table', 3); 
foreach($table->find('tr') as $row) { 
// initialize array to store the cell data from each row 
$rowData = array(); 
foreach($row->find('td') as $cell) { 
// push the cell's text to the array 
$rowData[] = $cell->innertext; 
} 
echo "<table>"; 
echo "<td>"; 
echo $rowData[0]. " "; 
echo "</td>"; 
echo "<td>"; 
echo $rowData[1]. " "; 
echo "</td>"; 
echo "<td>"; 
echo $rowData[2]. " "; 
echo "</td>"; 
echo "<td>"; 
echo $rowData[3]. " "; 
echo "</td>"; 
echo "<td>"; 
echo $rowData[4]. " "; 
echo "</td>"; 
echo "<td>"; 
echo $rowData[5]. " "; 
echo "</td>"; 
echo "<td>"; 
echo $rowData[6]. " "; 
echo "</td>"; 
echo "<td>"; 
echo $rowData[7]. " "; 
echo "</td>"; 
echo "<td>"; 
echo $rowData[8]. " "; 
echo "</td>"; 
echo "</table>"; 
} 
?> 
+2

Quindi queste sono quasi due domande separate. Il primo è quello di analizzare i dati in un formato di matrice che è possibile utilizzare e il secondo di produrre l'array in un formato desiderabile. Potrebbe aiutare a risolvere il primo problema prima. Per fare ciò, sarebbe utile vedere un output 'var_dump ($ rowData)' insieme alla struttura dati che si sta cercando di ottenere. –

+0

Hey Mike, il dump sembra questo (in questo momento): http://pastebin.com/KD6zP4Ui – loplo

+0

che assomiglia a due dump di varietà uno accanto all'altro. Quale è da $ rowData? Se è il secondo array, il tuo codice di visualizzazione non funziona perché hai un array multidimensionale. e l'eco di un array ti darà il vuoto. –

risposta

12

Forse prova a mettere ogni riga in un array e poi ogni cella in un altro array. Spero che ciò faccia ciò che vuoi.

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

Nota: questa soluzione richiede la libreria simple_html_dom.php. Get it here!

Problemi correlati