I am trying to replace empty field with \N
in my csv. To do that I am reading the existing csv and after doing some check. I am writing csv row to temp file but this temp file add double quote around the string.
I am using fputcsv()
for this purpose. Is there any way to escape these double quotes?
$ebayorderfile = 'ebay.csv';
$fh = fopen($ebayorderfile, 'r');
$headings = fgetcsv($fh, 0, ',');
$num = count($headings);
$tempfile = tempnam("/orders","tmp");
$output = fopen($tempfile,'w');
fputcsv($output,$headings);
while (($row = fgetcsv($fh, 0, ',')) !== FALSE) {
$row++;
$lineString=array();
for ($c=0; $c < $num; $c++) {
if(strlen($row[$c])<1){
$row[$c] = "\N";
}
array_push($lineString,$row[$c]);
}
fputcsv($output,$lineString);
}
fclose($fh);
fclose($output);
unlink($ebayorderfile);
rename($tempfile,$ebayorderfile);