我试图找出如何获取fgetcsv返回的数据,并将其格式化为可读/可编辑的表,然后使用fputcsv保存该表
到目前为止,我有这个<?php
$row = 1;
$handle = fopen("csv.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "\n";
}
}
fclose($handle);
?>
答案 0 :(得分:2)
以下代码将在html表格中输出CSV。为了使它可编辑包装echo .. $ val .. with tags并添加一个php表单处理程序,它获取结果并重新构建CSV
<?php
$row = 1;
$handle = fopen("csv.csv", "r");
echo("<table>");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
echo("<tr>\r\n");
foreach ($data as $index=>$val) {
echo("\t<td>$val</td>\r\n");
}
echo("</tr>\r\n");
}
echo("</table>");
fclose($handle);
?>