Simplify table output - always quote fields with "quotes" and that way, if there's a quote on the inside, it'll properly be quoted as a double quote, and if its at the beginning, it'll be a triple quote and work properly-

eg:
"field1","""my title is in quotes""","another field"
This commit is contained in:
james 2010-02-16 21:42:55 +00:00
parent 2539a1726f
commit 58c321441d

View File

@ -72,18 +72,11 @@ class lcsv
if($table['data']) {
foreach($table['data'] AS $dataline) {
for($c=0;$c<$table_cols;$c++) {
$quote = false;
//if the data contains the separator, we need to puti the data inside ""'s
if(strstr($dataline[$c],$this->separator())) $quote = true;
/* If it contains a newline, also quote it */
if(strchr($dataline[$c], "\n")) $quote = true;
//escape a single " with ""
$dataline_c=str_replace('"','""',$dataline[$c]);
if($quote == true)
//lets always quote it
$this->csvdata.="\"".$dataline_c."\"";
else
$this->csvdata.=$dataline_c;
if($c<$table_cols-1)
$this->csvdata.=$this->separator();