forked from science-ation/science-ation
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:
parent
2539a1726f
commit
58c321441d
13
lcsv.php
13
lcsv.php
@ -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)
|
||||
$this->csvdata.="\"".$dataline_c."\"";
|
||||
else
|
||||
$this->csvdata.=$dataline_c;
|
||||
|
||||
//lets always quote it
|
||||
$this->csvdata.="\"".$dataline_c."\"";
|
||||
|
||||
if($c<$table_cols-1)
|
||||
$this->csvdata.=$this->separator();
|
||||
|
Loading…
Reference in New Issue
Block a user