Skip to content

Commit

Permalink
Merge pull request #4 from bazen/remove-bom
Browse files Browse the repository at this point in the history
fix(CsvService): remove BOM
  • Loading branch information
bazen authored Nov 28, 2024
2 parents eb4c305 + 44e44da commit 3b86aaf
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Classes/CsvService.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ public function read($fileName = null, $csvOptions = null) {
if ($handle === FALSE) {
throw new \Exception('No Handle');
}

// BOM as a string for comparison.
$bom = "\xef\xbb\xbf";

// Progress file pointer and get first 3 characters to compare to the BOM string.
if (fgets($handle, 4) !== $bom) {
// BOM not found - rewind pointer to start of file.
rewind($handle);
}

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

}

}
}

0 comments on commit 3b86aaf

Please sign in to comment.