Sto cercando di analizzare la tabella mostrata here in un array php multidimensionale. Sto usando il seguente codice ma per qualche motivo restituisce un array vuoto. Dopo aver cercato sul web, ho trovato this site, da cui ho ricevuto la funzione parseTable(). Leggendo i commenti su quel sito, vedo che la funzione funziona perfettamente. Quindi presumo ci sia qualcosa di sbagliato nel modo in cui ottengo il codice HTML da file_get_contents(). Qualche idea su cosa sto facendo male?Analizzare la tabella html utilizzando file_get_contents su php array
<?php
$data = file_get_contents('http://flow935.com/playlist/flowhis.HTM');
function parseTable($html)
{
// Find the table
preg_match("/<table.*?>.*?<\/[\s]*table>/s", $html, $table_html);
// Get title for each row
preg_match_all("/<th.*?>(.*?)<\/[\s]*th>/", $table_html[0], $matches);
$row_headers = $matches[1];
// Iterate each row
preg_match_all("/<tr.*?>(.*?)<\/[\s]*tr>/s", $table_html[0], $matches);
$table = array();
foreach($matches[1] as $row_html)
{
preg_match_all("/<td.*?>(.*?)<\/[\s]*td>/", $row_html, $td_matches);
$row = array();
for($i=0; $i<count($td_matches[1]); $i++)
{
$td = strip_tags(html_entity_decode($td_matches[1][$i]));
$row[$row_headers[$i]] = $td;
}
if(count($row) > 0)
$table[] = $row;
}
return $table;
}
$output = parseTable($data);
print_r($output);
?>
voglio che il mio array di uscita a guardare qualcosa di simile:
1 --> 11:33AM --> DEV --> IN THE DARK 2 --> 11:29AM --> LIL' WAYNE --> SHE WILL 3 --> 11:26AM --> KARDINAL OFFISHALL --> NUMBA 1 (TIDE IS HIGH)
-1 per mancanza di impegno. isolare il problema invece di fondamentalmente la pubblicazione di un enorme blocco di codice e chiedendo alla gente di fig Scopri cosa c'è che non va e risolvilo. – NullUserException