hereの表を多次元PHP配列に解析しようとしています。私は次のコードを使用していますが、何らかの理由で空の配列を返しています。 Web上で検索した後、私はthis siteを見つけました。そこにはparseTable()関数があります。そのウェブサイトのコメントを読んでから、私はその機能が完璧に機能していることがわかります。ですから、私はfile_get_contents()からHTMLコードを取得する方法に何か問題があると仮定しています。私が間違ってやっていることに関する考えは?phtml配列にfile_get_contentsを使用してhtmlテーブルを解析する
<?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);
?>
私は私の出力配列は、このような何かを見てみたい:
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。代わりに、基本的にコードの巨大なブロックを掲示するのあなたの問題を特定し、人々にイチジクを求める何が間違っているかを確認して修正してください。 – NullUserException