ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCSVUtil.php
Go to the documentation of this file.
1 <?php
2 
19 class ilCSVUtil
20 {
33  public static function &processCSVRow(
34  array &$row,
35  bool $quoteAll = false,
36  string $separator = ';',
37  bool $outUTF8 = false,
38  bool $compatibleWithMSExcel = true
39  ): array {
40  $resultarray = [];
41  foreach ($row as $rowindex => $entry) {
42  $surround = false;
43  if ($quoteAll) {
44  $surround = true;
45  }
46  if (str_contains($entry, '"')) {
47  $entry = str_replace('"', '""', $entry);
48  $surround = true;
49  }
50  if (str_contains($entry, $separator)) {
51  $surround = true;
52  }
53  if ($compatibleWithMSExcel) {
54  // replace all CR LF with LF (for Excel for Windows compatibility
55  $entry = str_replace(chr(13) . chr(10), chr(10), $entry);
56  }
57  if ($surround) {
58  if ($outUTF8) {
59  $resultarray[$rowindex] = '"' . $entry . '"';
60  } else {
61 
62  $resultarray[$rowindex] = iconv('UTF-8', 'ISO-8859-1', '"' . $entry . '"');
63  }
64  } elseif ($outUTF8) {
65  $resultarray[$rowindex] = $entry;
66  } else {
67  $resultarray[$rowindex] = iconv('UTF-8', 'ISO-8859-1', $entry);
68  }
69  }
70  return $resultarray;
71  }
72 }
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...