ILIAS  trunk Revision v11.0_alpha-1851-ga8564da6fed
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 19 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 33 of file class.ilCSVUtil.php.

Referenced by ilObjUserFolder\createCSVExport().

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

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