From 7c7cb2ad8525b361eaacb2a0cae9c717c4a9a18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Tue, 22 May 2018 11:50:57 +0200 Subject: [PATCH] Remove BOM when parsing file; fixes #74 --- inc/backendcsv.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/inc/backendcsv.class.php b/inc/backendcsv.class.php index f71329ea..80744a81 100644 --- a/inc/backendcsv.class.php +++ b/inc/backendcsv.class.php @@ -198,6 +198,14 @@ function getNumberOfLines() { function openFile() { $this->file_handler = fopen($this->file, 'r'); + + // Check if file starts with BOM. + // 1. If BOM found, keep the handler moved to 4th char to not include it in data. + // 2. If no BOM found, rewind to start of file. + $hasBOM = fread($this->file_handler, 3) === pack('CCC', 0xEF, 0xBB, 0xBF); + if (!$hasBOM) { + fseek($this->file_handler, 0); + } }