note 103987 added to function.fputcsv

From: Date: Mon, 16 May 2011 02:09:04 +0000
Subject: note 103987 added to function.fputcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-179744@lists.php.net to get a copy of this message
These two handy functions allow you to use fgetcsv with a string instead of a file handle and fputcsv to convert an array to a string instead of writing to a file handle. Hopefully this functionality will exist natively soon. Props to prior notes on these functions that led me to these. <?php function array_to_CSV($data) { $outstream = fopen("php://temp", 'r+'); fputcsv($outstream, $data, ',', '"'); rewind($outstream); $csv = fgets($outstream); fclose($outstream); return $csv; } function CSV_to_array($data) { $instream = fopen("php://temp", 'r+'); fwrite($instream, $data); rewind($instream); $csv = fgetcsv($instream, 9999999, ',', '"'); fclose($instream); return($csv); } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 63.255.112.210 ---- Manual Page -- http://www.php.net/manual/en/function.fputcsv.php Edit -- https://master.php.net/note/edit/103987 Del: integrated -- https://master.php.net/note/delete/103987/integrated Del: useless -- https://master.php.net/note/delete/103987/useless Del: bad code -- https://master.php.net/note/delete/103987/bad+code Del: spam -- https://master.php.net/note/delete/103987/spam Del: non-english -- https://master.php.net/note/delete/103987/non-english Del: in docs -- https://master.php.net/note/delete/103987/in+docs Del: other reasons-- https://master.php.net/note/delete/103987 Reject -- https://master.php.net/note/reject/103987 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179744) next »