$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>
";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />
";
}
}
fclose($handle);
}
<?php
ini_set('auto_detect_line_endings',TRUE);
$handle = fopen('/path/to/file','r');
while ( ($data = fgetcsv($handle) ) !== FALSE ) {
//process the array in $data
var_dump($data);
}
ini_set('auto_detect_line_endings',FALSE);
<!DOCTYPE html>
<html>
<body>
<center>
<h1>DISPLAY DATA PRESENT IN CSV</h1>
<h3>Student data</h3>
<?php
echo "<html><body><center><table>
";
// Open a file
$file = fopen("a.csv", "r");
// Fetching data from csv file row by row
while (($data = fgetcsv($file)) !== false) {
// HTML tag for placing in row format
echo "<tr>";
foreach ($data as $i) {
echo "<td>" . htmlspecialchars($i)
. "</td>";
}
echo "</tr>
";
}
// Closing the file
fclose($file);
echo "
</table></center></body></html>";
?>
</center>
</body>
</html>