xxxxxxxxxx
<?php
$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>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}
?>
xxxxxxxxxx
$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>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}
xxxxxxxxxx
<?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);
xxxxxxxxxx
<!DOCTYPE html>
<html>
<body>
<center>
<h1>DISPLAY DATA PRESENT IN CSV</h1>
<h3>Student data</h3>
<?php
echo "<html><body><center><table>\n\n";
// 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> \n";
}
// Closing the file
fclose($file);
echo "\n</table></center></body></html>";
?>
</center>
</body>
</html>
xxxxxxxxxx
<?php
$CSVfp = fopen("fruits.csv", "r");
if ($CSVfp !== FALSE) {
?>
<div class="phppot-container">
<table class="striped">
<thead>
<tr>
<th>NAME</th>
<th>COLOR</th>
</tr>
</thead>
<?php
while (! feof($CSVfp)) {
$data = fgetcsv($CSVfp, 1000, ",");
if (! empty($data)) {
?>
<tr class="data">
<td><?php echo $data[0]; ?></td>
<td><div class="property-display"
style="background-color: <?php echo $data[2]?>;"><?php echo $data[1]; ?></div></td>
</tr>
<?php }?>
<?php
}
?>
</table>
</div>
<?php
}
fclose($CSVfp);
?>