<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CSVファイルを読み込みたい</title>
</head>
<body>
<?php
$csvFile = '01-2.csv';
$tempCSV = file_get_contents($csvFile);
$tempCSV = mb_convert_encoding($tempCSV, 'UTF-8', 'SJIS-win');
$fp = tmpfile();
fwrite($fp, $tempCSV);
rewind($fp);
setlocale(LC_ALL, 'ja_JP.UTF-8');
$html = '<table border="1">';
while ($arr = fgetcsv($fp, 1024)) {
if (!(count($arr) == 1 && $arr[0] == '')) {
list($youbi, $main, $dessert) = $arr;
$html .= '<tr>'
. "<td>" . h($youbi) . "</td>"
. "<td>" . h($main) . "</td>"
. "<td>" . h($dessert) . "</td>"
. '</tr>';
}
}
$html .= '</table>';
fclose($fp);
echo $html;
function h($string) {
return htmlspecialchars($string, ENT_QUOTES);
}
?>
</body>
</html>