ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilCSVUtil.php
Go to the documentation of this file.
1 <?php
2 
20 class ilCSVUtil
21 {
34  public static function &processCSVRow(
35  array &$row,
36  bool $quoteAll = false,
37  string $separator = ';',
38  bool $outUTF8 = false,
39  bool $compatibleWithMSExcel = true
40  ): array {
41  $resultarray = [];
42  foreach ($row as $rowindex => $entry) {
43  $surround = false;
44  if ($quoteAll) {
45  $surround = true;
46  }
47  if (str_contains($entry, '"')) {
48  $entry = str_replace('"', '""', $entry);
49  $surround = true;
50  }
51  if (str_contains($entry, $separator)) {
52  $surround = true;
53  }
54  if ($compatibleWithMSExcel) {
55  // replace all CR LF with LF (for Excel for Windows compatibility
56  $entry = str_replace(chr(13) . chr(10), chr(10), $entry);
57  }
58  if ($surround) {
59  if ($outUTF8) {
60  $resultarray[$rowindex] = '"' . $entry . '"';
61  } else {
62 
63  $resultarray[$rowindex] = iconv('UTF-8', 'ISO-8859-1', '"' . $entry . '"');
64  }
65  } elseif ($outUTF8) {
66  $resultarray[$rowindex] = $entry;
67  } else {
68  $resultarray[$rowindex] = iconv('UTF-8', 'ISO-8859-1', $entry);
69  }
70  }
71  return $resultarray;
72  }
73 }
static & processCSVRow(array &$row, bool $quoteAll=false, string $separator=';', bool $outUTF8=false, bool $compatibleWithMSExcel=true)
Convertes an array for CSV usage.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...