ILIAS  release_8 Revision v8.24
class.ilCSVUtil.php
Go to the documentation of this file.
1<?php
2
3/******************************************************************************
4 *
5 * This file is part of ILIAS, a powerful learning management system.
6 *
7 * ILIAS is licensed with the GPL-3.0, you should have received a copy
8 * of said license along with the source code.
9 *
10 * If this is not the case or you just want to try ILIAS, you'll find
11 * us at:
12 * https://www.ilias.de
13 * https://github.com/ILIAS-eLearning
14 *
15 *****************************************************************************/
16
17
19{
32 public static function &processCSVRow(
33 array &$row,
34 bool $quoteAll = false,
35 string $separator = ";",
36 bool $outUTF8 = false,
37 bool $compatibleWithMSExcel = true
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 }
72}
static & processCSVRow(array &$row, bool $quoteAll=false, string $separator=";", bool $outUTF8=false, bool $compatibleWithMSExcel=true)
Convertes an array for CSV usage.