namibia
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<?php
namespace Utility\Export;
class Csv
{
private $_file;
private $_fileHandle;
private $_delimiter = ',';
private $_enclosure = '"';
private $_escape = '\\';
private $_recordLength = 0;
const WRITE_OVERWRITE = 1;
const WRITE_APPEND = 2;
public function __construct($file, $writeMethod = self::WRITE_OVERWRITE)
{
$this->_file = $file;
$method = self::WRITE_OVERWRITE == $writeMethod
? 'w'
: 'a';
$this->_fileHandle = fopen($this->_file, $method);
if (!$this->_fileHandle)
{
throw new \Exception('File ' . $this->_file . ' could not be opened for writing');
}
}
public function setDelimiter($delimiter)
{
$this->_delimiter = $delimiter;
if (!empty($this->_headers))
{
$this->reset();
$this->_headers = $this->getRecord(self::FETCH_LAZY);
}
}
public function setEnclosure($enclosure)
{
$this->_enclosure = $enclosure;
}
public function setEscape($escape)
{
$this->_escape = $escape;
}
public function setRecordLength($length)
{
$this->_recordLength = $length;
}
/**
* Writes a record to the file
* @return array
*/
public function putRecord($record)
{
$bytesWritten = fputcsv($this->_fileHandle, $record, $this->_delimiter, $this->_enclosure);
return 0 < $bytesWritten
? true
: false;
}
public function __destruct()
{
if ($this->_fileHandle)
{
fclose($this->_fileHandle);
}
}
}
|
Revision |
Author |
Commited |
Message |
df0489 ...
|
Mark |
Fri 14 Oct, 2016 10:01:00 +0000 |
|