I'm writing a complex object into CSV. There are strings containing \"
in the object. When fputcsv
encoding the object into CSV using json, it doesn't encode \"
to \""
,so I can't processing the CSV file correctly. How can I encode the object correctly using fputcsv
? Or how can I process the csv like that?
PHP 5.6.39 Mac OS 10.14.4 Nginx 1.15.8
$fileName = 'test.csv';
$file = fopen($fileName, 'a+');
$json = '[{"action":"{\"type\":\"showSearch\"}","time":1552458671}]';
$value = [$json];
fputcsv($file, $value);
fclose($file);
Expected output:
"[{""action"":""{\""type\"":\""showSearch\""}"",""time"":1552458671}]"
Actual output:
"[{""action"":""{\"type\":\"showSearch\"}"",""time"":1552458671}]"