我一直在使用脚本将我的CSV文件更改为Tab Delimited。它似乎工作得很好,但它是只读的。如何实际将更改写入文件?这是脚本:
<?php
$myfile = "/path/to/my.csv";
$csv_fp = fopen ($myfile, "r");
$rows = 0;
while ($data = fGetCsv ($csv_fp, 10000, ","))
{
$num = count($data);
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
$rows++;
}fclose ($csv_fp);
?>
答案 0 :(得分:2)
这是您可以将逗号分隔的CSV更改为以制表符分隔的方式。但是,我没有看到这样做的好处。我认为以逗号分隔的CSV不太容易出错。
<?php
$myfile = "/path/to/my.csv";
$csv_fread = fopen($myfile, 'r');
$rows = array();
while ($columns = fgetcsv($csv_fread, 10000, ",")) {
$rows[] = $columns;
}
fclose($csv_fread);
$csv_fwrite = fopen($myfile, 'w');
foreach($rows as $row){
fputcsv($csv_fwrite, $row, "\t");
}
fclose($csv_fwrite);
?>
答案 1 :(得分:0)