Hi. I have this code, it works. $arch = fopen('sales.csv', 'w+'); fputs($arch, "Code, Name, Amount".PHP_EOL); $sql = "SELECT code, name, amount from table"; $sth = $BD->query($sql); $sth->execute(); if ($sth->rowCount() > 0) { while ($fila = $sth->fetch(PDO::FETCH_ASSOC)){ fputs($arch, implode($fila, ',').PHP_EOL); } } fclose($arch); PHP: The csv file show this records. There are ok. Code, Name, Amount 178,CAÑAVERAL,45.00 677,DIVINO NIÑO,30.00 679,HUACHO,15.00 2291,D' VANIA,120.00 2297,SEÑOR DEL MAR,150.00 Code (markup): When the csv file is opened with Excel (users using Excel), show this: Código Nombre Importe 178 CAÑAVERAL 45 677 DIVINO NIÑO 30 679 HUACHO 15 2291 D' VANIA 120 2297 SEÑOR DEL MAR 150 Code (markup): How I do to show the corrects characters? Thanks.
The Windows operating system (Windows 7+) has a setting for the 'list separator'. In Windows 10: To change Settings -> Time & Language -> Additional date, time & regional setting (at the bottom of the screen) -> change date, time or number formats -> Additional settings ... (Button) The List Separator field is the field that sets this.
I'd be looking at this line fputs($arch, implode($fila, ',').PHP_EOL); //and trying this fputs($arch, '"'.implode($fila, '","').'"'.PHP_EOL); //or this fputs($arch, '"'.implode($fila, "\"\t\"").'"'.PHP_EOL); PHP: