With this code I create my CSV export file:
foreach ($data_for_export as $row) {
$data = [];
array_push($data, $row->product_id);
array_push($data, $row->product_name);
array_push($data, $row->product_code);
array_push($data, $row->text);
fputcsv($file, $data);
}
fclose($file);
Example output is:
2131,"Toys set 35", TSSET35, "Lorem ipsum dolor sit amet"
I tried it with:
preg_replace("/([a-z0-9]+)/i", '"$1"', $row->product_id)
'"'.$row->product_id.'"'
With "preg_replace" I get some times more quotes then needed...
I need there quotes on all export items, how can I do that?