Reputation: 83
How can I write quotation marks ("") in csv files using fputcsv. I tried:
'""'
the result is written to csv file as """""""
"\"\""
The result is written to the csv file as \"\"
Upvotes: 3
Views: 1661
Reputation: 1140
fputcsv
is escaping the double quotes because it uses a double quote as the default enclosure character for each field it writes. You can change which character fputcsv
uses by passing a new character as a parameter to the function:
$fh = fopen('filename.csv', 'w');
$data = ['""'];
$delimiter = ','; // keep the delimiter as a comma
$enclosure = "'"; // set the enclosure to a single quote
fputcsv($fh, $data, $delimiter, $enclosure);
fclose($fh);
See: https://www.php.net/manual/en/function.fputcsv.php
Upvotes: 2