ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCSVWriter.php
Go to the documentation of this file.
1<?php
2
20{
21 private string $csv = '';
22 private string $separator = ',';
23 private string $delimiter = '"';
24 private string $new_line = "\n";
25 private bool $first_entry = true;
26
27 public function setSeparator(string $a_sep): void
28 {
29 $this->separator = $a_sep;
30 }
31
32 public function setDelimiter(string $a_del): void
33 {
34 $this->delimiter = $a_del;
35 }
36
37 public function addRow(): void
38 {
39 $this->csv .= $this->new_line;
40 $this->first_entry = true;
41 }
42
43 public function addColumn(string $a_col): void
44 {
45 if (!$this->first_entry) {
46 $this->csv .= $this->separator;
47 }
48 $this->csv .= $this->delimiter;
49 $this->csv .= $this->quote($a_col);
50 $this->csv .= $this->delimiter;
51 $this->first_entry = false;
52 }
53
54 public function getCSVString(): string
55 {
56 return $this->csv;
57 }
58
59 private function quote(string $a_str): string
60 {
61 return str_replace(
62 $this->delimiter,
63 $this->delimiter . $this->delimiter,
64 $a_str
65 );
66 }
67}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
quote(string $a_str)
setDelimiter(string $a_del)
setSeparator(string $a_sep)
addColumn(string $a_col)