PoorDeveloper
PoorDeveloper

Reputation: 186

Special characters encoding during CSV import

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

Additional info

Upvotes: 3

Views: 5710

Answers (1)

Ather Parvez
Ather Parvez

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

Related Questions