简体   繁体   中英

How to generate a CSV file with accented characters using PHP?

Accented characters like enie (ñ) are difficult to handle when generating CSV files. The tendency is one might end up having different and unexpected characters.

In my case, the CSV file I generated got a \\1\\1 instead of ñ . Thus instead of having Niño it got Ni\\1\\1o .

Is this even possible to fix? How to generate a CSV file with accented characters using PHP?

您可以编码数据检查

http://php.net/manual/en/function.mb-convert-encoding.php

You can try this

header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename=Customers_Export.csv');
echo "\xEF\xBB\xBF";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM