Added support for mb_convert_encoding() instead of iconv()

See issue #109 at GitHub
This commit is contained in:
Christian Bläul
2018-01-21 15:02:25 +01:00
committed by Fonata
parent 5ea1d95f31
commit 8ae09c604b
2 changed files with 22 additions and 15 deletions

View File

@@ -220,6 +220,16 @@ class parseCSV {
*/
public $output_encoding = 'ISO-8859-1';
/**
* Whether to use mb_convert_encoding() instead of iconv().
*
* The former is platform-independent whereas the latter is the traditional
* default go-to solution.
*
* @var bool (if false, iconv() is used)
*/
public $use_mb_convert_encoding = false;
/**
* Linefeed
* Line feed characters used by unparse, save, and output methods
@@ -817,7 +827,9 @@ class parseCSV {
}
if ($this->convert_encoding && $this->input_encoding !== $this->output_encoding) {
$data = iconv($this->input_encoding, $this->output_encoding, $data);
$data = $this->use_mb_convert_encoding ?
mb_convert_encoding($data, $this->output_encoding, $this->input_encoding) :
iconv($this->input_encoding, $this->output_encoding, $data);
}
if (substr($data, -1) != "\n") {