Here's another way I was working on this yesterday:
<?php
$cnx = fopen("data/Book1.csv", "r"); //open csv file
echo("<table>\n\t<tbody>\n"); // echo the table
while (!feof ($cnx)) { // while not end of file
$buffer = fgets($cnx); // get contents of file (name) as variable
$values = explode(",", $buffer); //explode "," between the values within the contents
echo "\t\t<tr>\n";
for ( $i = 0; $i < count($values); $i++ ) { //
if ( $i === 0 ) {
echo("\t\t\t<th>$values[$i]</th>\n");
} else {
echo("\t\t\t<td>$values[$i]</td>\n");
}
}
echo"\t\t</tr>\n";
};
echo("\t</tbody>\n</table>");
fclose($cnx); //close filename variable
?>
Which worked, except that it made the first "column" <th> cells rather than the first "row".