lundi 12 février 2018

Generate CSV with quotes base on PHP array [duplicate]

This question already has an answer here:

I'm trying to generate a csv file with PHP array

If I did this

$fp = fopen('csv/languages.csv', 'w');
  foreach ($final_new_array as $row) {
      fputcsv($fp, $row);
  }
  fclose($fp);

I got the languages.csv generated, but when I open it up. I saw some fields have quotes some not.

See this image below.

enter image description here

I want to make sure to generate quotes for all the cells to be consistent, so I have tried.

$fp = fopen('csv/languages.csv', 'w');
foreach ($final_new_array as $row) {
    fputcsv($fp, implode(',',array_walk($row, '"'.$row.'"')));
}
fclose($fp);

I kept getting error

Array to string conversion



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire