Skip to content

Commit 3b86aaf

Browse files
authored
Merge pull request #4 from bazen/remove-bom
fix(CsvService): remove BOM
2 parents eb4c305 + 44e44da commit 3b86aaf

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Diff for: Classes/CsvService.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,14 @@ public function read($fileName = null, $csvOptions = null) {
166166
if ($handle === FALSE) {
167167
throw new \Exception('No Handle');
168168
}
169-
169+
// BOM as a string for comparison.
170+
$bom = "\xef\xbb\xbf";
171+
172+
// Progress file pointer and get first 3 characters to compare to the BOM string.
173+
if (fgets($handle, 4) !== $bom) {
174+
// BOM not found - rewind pointer to start of file.
175+
rewind($handle);
176+
}
170177

171178
$this->data = array();
172179
while (($columnData = fgetcsv($handle, 0, $csvOptions['delimiter'], $csvOptions['enclosure'])) !== FALSE) {
@@ -439,4 +446,4 @@ protected function analyzeCsv() {
439446

440447
}
441448

442-
}
449+
}

0 commit comments

Comments
 (0)