Folder Structure:
index.php
<!DOCTYPE html>
<html>
<head>
<title>Web Application.</title>
</head>
<body>
<?php
/* $list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('aaa', 'bbb', 'ccc', 'dddd'),
array('aaa', 'bbb', 'ccc', 'dddd')
);
$fp = fopen('file.csv', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}*/
function ddataReadcsv($filename, $header=false) {
$handle = fopen($filename, "r");
echo '<table border=1>';
if ($header) {
$csvcontents = fgetcsv($handle);
echo '<tr>';
foreach ($csvcontents as $headercolumn) {
echo "<th>$headercolumn</th>";
}
echo '</tr>';
}
while ($csvcontents = fgetcsv($handle)) {
echo '<tr>';
foreach ($csvcontents as $column) {
echo "<td>$column</td>";
}
echo '</tr>';
}
echo '</table>';
fclose($handle);
}
ddataReadcsv('file.csv',true);
?>
</body>
</html>
Output:
0 comments:
Post a Comment