Skip to content

Commit

Permalink
Add posibility to keep the given header format when writting a csv file.
Browse files Browse the repository at this point in the history
git-svn-id: http://voip.null.ro/svn/ansql/trunk@310 dbfed7de-b0aa-0410-b6a1-c7e608b77fc9
  • Loading branch information
dana committed Apr 6, 2017
1 parent 657df27 commit 4dc07e9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ class CsvFile extends GenericFile
public $file_content = array();
private $formats = array();
private $sep;
private $change_header;

function __construct($file_name, $formats, $file_content=array(), $test_header=true, $read=true, $sep=",")
function __construct($file_name, $formats, $file_content=array(), $test_header=true, $read=true, $sep=",", $change_header=true)
{
Debug::func_start(__METHOD__,func_get_args(),"ansql");
parent::__construct($file_name);
$this->formats = $formats;
$this->sep = $sep;
$this->file_content = $file_content;
$this->test_header = $test_header;
$this->change_header = $change_header;

if ($read)
$this->read();
Expand Down Expand Up @@ -243,8 +245,12 @@ function write($key_val_arr=true, $col_header=true)
if(is_numeric($column_name))
$name = $var_name;
}
$val = str_replace("_"," ",ucfirst($name));
$val = str_replace(" "," ",$val);
if ($this->change_header) {
$val = str_replace("_"," ",ucfirst($name));
$val = str_replace(" "," ",$val);
} else {
$val = $name;
}
$val = ($col_nr) ? $this->sep."\"$val\"" : "\"$val\"";
fwrite($this->write_handler, $val);
if ($col_nr%10 == 0 && $this->exceeded_script_memory())
Expand Down

0 comments on commit 4dc07e9

Please sign in to comment.