L
L
Lu_den2017-06-05 11:47:32
PHP
Lu_den, 2017-06-05 11:47:32

How to generate CSV in PHP that will be displayed correctly everywhere?

It seems to be a simple task to make CSV.
I create it with , then convert from UTF-8 to Windows-1251 with iconv. For most users, it opens correctly, you can immediately work with columns. But for many text fields - in krakozyabry.
fputcsv($fp, $fields,";");

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2017-06-05
@Lu_den

It's about the BOM

$fp = fopen('testcsv.csv', 'w');
fputs($fp, chr(0xEF) . chr(0xBB) . chr(0xBF)); // BOM
fputcsv($fp, array('Item', 'Столбец 1', 'Данные'), ';');
fclose($fp);

D
Dimonchik, 2017-06-05
@dimonchik2013

and why in windows-1251?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question