0
It is possible to prevent the file CSV
come with aspas duplas
in string fields, I am using the script below, but the field nome
is coming between aspas duplas
, how can I avoid this?
<?php
//export.php
if(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
Julio Neto’s response usingfwrite
andimplode
served, just add line break in the last query field to avoid joining the last field with the first of each line, as follows::
..., concat(siem_id,"\n") from cs_gabarito';
Could edit the question and put an example of CSV output?
– fernandosavio
yes yes, a moment
– Miguel Silva
@fernandosavio added image
– Miguel Silva