note 104228 deleted from function.fputcsv by danbrown
| From: | danbrown@php.net | Date: | Thu, 02 Jun 2011 17:56:54 +0000 |
| Subject: | note 104228 deleted from function.fputcsv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180201@lists.php.net to get a copy of this message | ||
Note Submitter: ergecsenturk at gmail dot com
----
Christine's solution if a lifesaver except one problem. If you have columns having multi-line
data array_to_csv will fail so I did a small change on this function
function __replace_new_lines(&$value, $key) {
$value = str_replace("\n", " ", $value);
}
function array_to_csv($data) {
array_walk($data, '__replace_new_lines');
$outstream = fopen("php://temp", 'r+');
fputcsv($outstream, $data, ',', '"');
rewind($outstream);
$csv = fgets($outstream);
fclose($outstream);
return $csv;
}