_header = $header; } /** * Add a row of data. */ public function addRow (array $row) { $this->_data[] = $row; } /** * Spit out a string containing the entire CSV. */ public function render() { $ret = ''; if(!empty($this->_header)) { foreach($this->_header as $field) { $ret .= '"' . str_replace('"', '""', addslashes($field)) . '",'; } $ret[strlen($ret) - 1] = "\n"; } foreach($this->_data as $row) { foreach($row as $field) { $ret .= '"' . str_replace('"', '""', addslashes($field)) . '",'; } $ret[strlen($ret) - 1] = "\n"; } return $ret; } }