note 109018 added to function.fputcsv

From: Date: Wed, 13 Jun 2012 08:06:05 +0000
Subject: note 109018 added to function.fputcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-188551@lists.php.net to get a copy of this message
The function array_to_CSV provided by Christine K - crimson at technologist dot com has a shortcoming: if the CSV in question contains newlines it will fail because rewind($outstream) will rewind to the start of the buffer, but fgets will just read until the first newline character. A better solution to fix this is: function array_to_CSV($data) { $outstream = fopen("php://temp", 'r+'); fputcsv($outstream, $data, ',', '"'); $len = ftell($outstream); rewind($outstream); $csv = fread($outstream, $len); fclose($outstream); return $csv; } ---- Server IP: 91.199.167.223 Probable Submitter: 94.212.48.17 ---- Manual Page -- http://www.php.net/manual/en/function.fputcsv.php Edit -- https://master.php.net/note/edit/109018 Del: integrated -- https://master.php.net/note/delete/109018/integrated Del: useless -- https://master.php.net/note/delete/109018/useless Del: bad code -- https://master.php.net/note/delete/109018/bad+code Del: spam -- https://master.php.net/note/delete/109018/spam Del: non-english -- https://master.php.net/note/delete/109018/non-english Del: in docs -- https://master.php.net/note/delete/109018/in+docs Del: other reasons-- https://master.php.net/note/delete/109018 Reject -- https://master.php.net/note/reject/109018 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188551) next »