Answer the question
In order to leave comments, you need to log in
How to fix encoding in CSV?
I write to a file and upload CSV in this way:
$data = [
'Товар 1;some;3',
'Товар 2;anather;6',
'Товар 3;test;9'
];
header('Content-Type: text/csv');
header('Content-disposition: attachment;filename=data.csv');
foreach ($data as $row) {
echo $row, PHP_EOL;
}
Answer the question
In order to leave comments, you need to log in
<?php
$data = [
'Товар 1;some;3',
'Товар 2;anather;6',
'Товар 3;test;9'
];
header('Content-Type: text/csv');
header('Content-disposition: attachment;filename=data.csv');
foreach ($data as $row) {
echo mb_convert_encoding($row, 'CP1251', mb_detect_encoding($row)), PHP_EOL;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question