note 103986 added to function.fgetcsv

From: Date: Mon, 16 May 2011 02:07:09 +0000
Subject: note 103986 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-179743@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.fgetcsv.php Edit -- https://master.php.net/note/edit/103986 Del: integrated -- https://master.php.net/note/delete/103986/integrated Del: useless -- https://master.php.net/note/delete/103986/useless Del: bad code -- https://master.php.net/note/delete/103986/bad+code Del: spam -- https://master.php.net/note/delete/103986/spam Del: non-english -- https://master.php.net/note/delete/103986/non-english Del: in docs -- https://master.php.net/note/delete/103986/in+docs Del: other reasons-- https://master.php.net/note/delete/103986 Reject -- https://master.php.net/note/reject/103986 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179743) next »