From 0ac5064d581f1b432ea55145a5a65bb534e03a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bl=C3=A4ul?= Date: Sat, 25 Nov 2017 13:47:54 +0100 Subject: [PATCH] Only call iconv if input and output encoding differ. This saves some headache if characters are invalid according to iconv. --- parsecsv.lib.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 7e29573..28ebb3d 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -843,19 +843,18 @@ class parseCSV { $data = substr($data, 3); $this->encoding('UTF-8'); } - else if (strpos($data, "\xff\xfe") === 0) { + elseif (strpos($data, "\xff\xfe") === 0) { // strip off BOM (UTF-16 little endian) $data = substr($data, 2); $this->encoding("UCS-2LE"); } - - else if (strpos($data, "\xfe\xff") === 0) { + elseif (strpos($data, "\xfe\xff") === 0) { // strip off BOM (UTF-16 big endian) $data = substr($data, 2); $this->encoding("UTF-16"); } - if ($this->convert_encoding) { + if ($this->convert_encoding && $this->input_encoding !== $this->output_encoding) { $data = iconv($this->input_encoding, $this->output_encoding, $data); }