Reputation: 186
I have script that read *.CSV file and then export it content to MSSQL Database. Script is running only via CLI.
My problem is that this CSV file contains string with national characters like ą,ó,ż,ź,ś
. For example i have word pracowników
but in CLI i see word pracownikˇw
.
My code
$handler = fopen($file, "r");
if ($handler !== false) {
while (($this->currentRow = fgetcsv($handler, 0, $this->csvDelimiter)) !== false) {
$row = $this->setHeaders(
$this->currentRow,
$this->config[$type]['columnMapping']
);
if ($row !== false) {
$this->dataImported[$type][] = $row;
}
}
fclose($handler);
}
What i tried
fgetcsv
with setlocale
or without - not working.fgetcsv
with fgets
and read each line via str_getcsv
- not working.utf8_encode
for each row - not working.Additional info
ANSII
, i tried to decoded it with iconv
but all special characters are always replace with some strange symbols, like showed before.Upvotes: 3
Views: 5710
Reputation: 33
On loop of $this->currentRow
try to use for each element which has special char.
echo mb_convert_encoding($data[$c],"HTML-ENTITIES","UTF-8");
Upvotes: 1