ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCSVUtil Class Reference
+ 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

Definition at line 18 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 32 of file class.ilCSVUtil.php.

Referenced by ilObjUserFolder\createCSVExport(), and ilObjAssessmentFolderGUI\exportLogObject().

38  : array {
39  $resultarray = [];
40  foreach ($row as $rowindex => $entry) {
41  $surround = false;
42  if ($quoteAll) {
43  $surround = true;
44  }
45  if (strpos($entry, "\"") !== false) {
46  $entry = str_replace("\"", "\"\"", $entry);
47  $surround = true;
48  }
49  if (strpos($entry, $separator) !== false) {
50  $surround = true;
51  }
52  if ($compatibleWithMSExcel) {
53  // replace all CR LF with LF (for Excel for Windows compatibility
54  $entry = str_replace(chr(13) . chr(10), chr(10), $entry);
55  }
56  if ($surround) {
57  if ($outUTF8) {
58  $resultarray[$rowindex] = "\"" . $entry . "\"";
59  } else {
60  $resultarray[$rowindex] = utf8_decode("\"" . $entry . "\"");
61  }
62  } else {
63  if ($outUTF8) {
64  $resultarray[$rowindex] = $entry;
65  } else {
66  $resultarray[$rowindex] = utf8_decode($entry);
67  }
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: