ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilCSVUtil Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilCSVUtil:

Static Public Member Functions

static & processCSVRow (array &$row, bool $quoteAll=false, string $separator=';', bool $outUTF8=false, bool $compatibleWithMSExcel=true)
 Convertes an array for CSV usage. More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Definition at line 20 of file class.ilCSVUtil.php.

Member Function Documentation

◆ processCSVRow()

static& ilCSVUtil::processCSVRow ( array &  $row,
bool  $quoteAll = false,
string  $separator = ';',
bool  $outUTF8 = false,
bool  $compatibleWithMSExcel = true 
)
static

Convertes an array for CSV usage.

Processes an array as a CSV row and converts the array values to correct CSV values. The "converted" array is returned

Parameters
array$rowThe array containing the values for a CSV row
bool$quoteAllIndicates to quote every value (=TRUE) or only values containing quotes and separators (=FALSE, default)
string$separatorThe value separator in the CSV row (used for quoting) (; = default)
Returns
array The converted array ready for CSV use
Deprecated:

Definition at line 34 of file class.ilCSVUtil.php.

Referenced by ilObjUserFolder\createCSVExport().

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  }
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: