I've got one problem with fputcsv function. When I introduce an enclosure parameter (double quotes) and execute it with php command in Ubuntu, php script not insert this parameter in csv file.
fputcsv($handle,$array,";",'"'); //One try
fputcsv($handle,$array,";","\""); //Second try
fputcsv($handle,$array,";",chr(34)); //Third try
fputcsv($handle,$array,";","""); //Fourth try
fputcsv($handle,$array,";","'"'"); //Fifth try
fputcsv($handle,$array,";",'"','"'); //Sixth try
fputcsv($handle,$array,";",$quote = '"'); //Seventh try
<?php
//An example JSON string.
$jsonString = file_get_contents('archivo.json');
$codificado = utf8_encode($jsonString);
//Decode the JSON and convert it into an associative array.
$jsonDecoded = json_decode($codificado, true);
//Give our CSV file a name.
$csvFileName = 'example.csv';
//Open file pointer.
$fp = fopen($csvFileName, 'w');
$firstLineKeys = false;
//Loop through the associative array.
foreach($jsonDecoded as $row){
if(empty($firstLineKeys)) {
$firstLineKeys = array_keys($row);
fputcsv($fp,$firstLineKeys,';','"');
$firstLineKeys = array_flip($firstLineKeys);
}
fputcsv($fp,array_merge($firstLineKeys,$row),';','"');
}
//Finally, close the file pointer.
fclose($fp);
?>
CSV file without double quotes in all fields.