From 58c321441d2edcac9588a5f16746a9025f044c7a Mon Sep 17 00:00:00 2001 From: james Date: Tue, 16 Feb 2010 21:42:55 +0000 Subject: [PATCH] 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" --- lcsv.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lcsv.php b/lcsv.php index 2749378..b21b7f1 100644 --- a/lcsv.php +++ b/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();