2
How to remove "double quotes" in TXT file extracted from mysqli with PHP.
PHP function to create file
// Export data in CSV format
public function exportCSV(){
$id = $this->input->get("id");
// file name
$filename = 'Avm_inventarios_'.date('d M Y H:i:s').'.txt';
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/txt");
// get data
$dados_db = $this->Inventarios_model->gerar_txt($id);
// file creation
$file = fopen('php://output', 'W');
$header = array();
fputcsv($file,$header);
foreach ($dados_db as $line){
//print_r($line);
fputcsv ($file,str_replace('"','',$line),"\n");
}
fclose($file);
exit;
}
database


Quotes are not being generated by the method
$this->Inventarios_model->gerar_txt($id);?– Wilson Faustino
No. printed data is without Quotation marks.
– Hugo Rutemberg
Have you tried using the fourth parameter as empty? So:
fputcsv($file,str_replace('"','',$line),"\n",'');– Wilson Faustino
using this way got the following error:
Message: fputcsv(): enclosure must be a characterfputcsv($file,str_replace('"','',$line),"\n",'');, however it does not bring all the spaces that exist in the table The Archive looks like this163836353095 00001when you should be like this163836353095 00001– Hugo Rutemberg
Hugo, do you have access to the database? You can transform the column where it is
00001to just1? I think that’s the optionZEROFILL. Thus, thefputcsvwill not put the quotes. I think we are trying to get around the variable problem$linebut who is putting the quotes is himselffputcsv.– Wilson Faustino