我需要将数据括在" "已经尝试了几件事,但我只会弄乱我的数据
我需要格式化输出 csv:
"数据","数据","数据"
下面显示的 IM 使用和显示的代码是从此处的另一个问题复制而来的。
if (($handle = fopen('DIRTY_'.$val['spider'].'.csv', 'r')) !== false) {
// read each line into an array
while (($data = fgetcsv($handle, 8192, ",")) !== false) {
// build a "line" from the parsed data
$line = join("," , $data );
// if the line has been seen, skip it
if (isset($lines[$line])) continue;
// save the line
$lines[$line] = true;
}
fclose($handle);
}
$contents = '';
foreach ($lines as $line => $bool) $contents .= $line . "'r'n";
file_put_contents($val['spider'].".csv", $contents);
}
使用 fgetcsv
和 fputcsv
。它会为你逃脱。
还值得一提的是,CSV不是一个定义明确的标准。有时是逗号分隔的,有时是分号,有时是制表符。有时"
始终存在,有时仅在您有换行符时才存在。