note 103986 deleted from function.fgetcsv by danbrown

From: Date: Mon, 16 May 2011 16:10:54 +0000
Subject: note 103986 deleted from function.fgetcsv by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179766@lists.php.net to get a copy of this message
Note Submitter: Christine K - crimson at technologist dot com ---- 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); } ?>

« previous php.notes (#179766) next »