EGOCMS  24.0
EGOTEC Content-Managament-System
CSV.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
7 class CSV
8 {
9  private $content;
10  private $fields = array();
11 
12  public function __construct($field_data = array())
13  {
14  $this->content = '';
15  $this->fields = $field_data;
16  }
17 
18  private function nextRow() {
19  $this->content = rtrim($this->content, ',') . "\r\n";
20  }
21 
22  public function addHeader($data = array()) {
23  foreach ($data as $key => $value) {
24  $this->addEntry($this->fields[$key], true);
25  }
26  $this->nextRow();
27  }
28 
29  private function addEntry($value, $boolean)
30  {
31  $this->content .= '"'.str_replace('"', '\"', $value).'"';
32  if ($boolean) {
33  $this->content .= ",";
34  }
35  }
36 
37  public function addContact($data = array())
38  {
39  foreach ($data as $key => $value) {
40  if ($this->fields[$key]) {
41  $this->addEntry(isset($value) ? $value : '', true);
42  }
43  }
44  $this->nextRow();
45  }
46 
47  public function getContacts() {
48  return $this->content;
49  }
50 }
Definition: CSV.php:8
getContacts()
Definition: CSV.php:47
addContact($data=array())
Definition: CSV.php:37
__construct($field_data=array())
Definition: CSV.php:12
addHeader($data=array())
Definition: CSV.php:22