From 2539a1726f7ddab870b947099ea7fbe9c1327fde Mon Sep 17 00:00:00 2001 From: james Date: Tue, 16 Feb 2010 21:21:56 +0000 Subject: [PATCH] escape " with "" --- lcsv.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lcsv.php b/lcsv.php index 8ffd5d29..2749378d 100644 --- a/lcsv.php +++ b/lcsv.php @@ -69,21 +69,21 @@ class lcsv } //now do the data in the table - if($table['data']) - { - foreach($table['data'] AS $dataline) - { - for($c=0;$c<$table_cols;$c++) - { + 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]."\""; + $this->csvdata.="\"".$dataline_c."\""; else - $this->csvdata.=$dataline[$c]; + $this->csvdata.=$dataline_c; if($c<$table_cols-1) $this->csvdata.=$this->separator();