0

我需要将我的数据包含在“”中已经尝试了几件事,但我只是弄乱了我的数据

我需要格式化输出 csv:
“数据”、“数据”、“数据”
我使用并显示在下面的代码是从此处的另一个问题复制而来的。

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);

}

4

1 回答 1

1

使用fgetcsvfputcsv。它会为你逃跑。

值得一提的是,CSV 并不是一个定义明确的标准。有时是逗号分隔,有时是分号,有时是制表符。有时"总是存在,有时只有当你有换行符时。

于 2013-10-25T08:56:52.770 回答