It is possible to prevent the CSV
file from coming with aspas duplas
in string fields, I am using the script below, but the nome
field is coming between aspas duplas
, how can I avoid this?
<?php//export.phpif(isset($_POST["export"]))
{
$connect = mysqli_connect("localhost", "root", "", "simrede");
if (mysqli_connect_errno())
{
echo "Falha ao fazer conexão: " . mysqli_connect_error();
}
// Set utf8
mysqli_set_charset($connect,"utf8");
$connect->set_charset('utf8');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=Gabaritos_OMR_Alunos-Simrede.csv');
$output = fopen("php://output", "w");
fputcsv($output, array('ROLLNO', 'NAME', 'CLASS', 'EMAILID', 'PHONENO'),';');
$query = 'SELECT ROLLNO, nome, concat(".",nivel,"ano"), concat(id,"@gmail.com"), siem_id from cs_gabarito';
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_assoc($result))
{
fputcsv($output, $row,";");
}
fclose($output);
}
?>
Edit
The answer from Júlio Neto usingfwrite
andimplode
served, it was enough to add line break in the last field of the query to avoid joining the last field with the first of each line, as follows:
..., concat(siem_id,"\n") from cs_gabarito';