diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 6b8c95e9828..b81f2ae704e 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -245,14 +245,21 @@ public function csv_from_result(CI_DB_result $query, $delim = ',', $newline = "\ } $out = substr($out, 0, -strlen($delim)).$newline; - + $unsafe_chars=array('=','+','-','@'); + // Next blast through the result array and build out the rows while ($row = $query->unbuffered_row('array')) { $line = array(); foreach ($row as $item) { - $line[] = $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure; + $first = $item[0]; + $prepend=''; + if (in_array($first, $unsafe_chars)); + $prepend="\t"; + } + + $line[] = $enclosure.$prepend.str_replace($enclosure, $enclosure.$enclosure, trim($item)).$enclosure; } $out .= implode($delim, $line).$newline; }