note 115656 added to function.str-getcsv
| From: | enmanuelcorvo at gmail dot com | Date: | Tue, 02 Sep 2014 20:49:46 +0000 |
| Subject: | note 115656 added to function.str-getcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200361@lists.php.net to get a copy of this message | ||
I always use this:
function convert_to_csv($input_array, $output_file_name, $delimiter)
{
/** open raw memory as file, no need for temp files */
$temp_memory = fopen('php://memory', 'w');
/** loop through array */
foreach ($input_array as $line) {
/** default php csv handler **/
fputcsv($temp_memory, $line, $delimiter);
}
/** rewrind the "file" with the csv lines **/
fseek($temp_memory, 0);
/** modify header to be downloadable csv file **/
header('Content-Type: application/csv');
header('Content-Disposition: attachement; filename="' . $output_file_name .
'";');
/** Send file to browser for download */
fpassthru($temp_memory);
}
/** Array to convert to csv */
$array_to_csv = Array(Array(12566, 'Enmanuel', 'Corvo'), Array(56544,
'John', 'Doe'), Array(78550, 'Mark', 'Smith'));
convert_to_csv($array_to_csv, 'report.csv', ',');
you can read the full post here:
<a href="http://webtricksandtreats.com/export-to-csv-php/">PHP
to CSV Download </a>
----
Server IP: 72.52.91.14
Probable Submitter: 67.205.222.34
----
Manual Page -- http://php.net/manual/en/function.str-getcsv.php
Edit -- https://master.php.net/note/edit/115656
Del: integrated -- https://master.php.net/note/delete/115656/integrated
Del: useless -- https://master.php.net/note/delete/115656/useless
Del: bad code -- https://master.php.net/note/delete/115656/bad+code
Del: spam -- https://master.php.net/note/delete/115656/spam
Del: non-english -- https://master.php.net/note/delete/115656/non-english
Del: in docs -- https://master.php.net/note/delete/115656/in+docs
Del: other reasons-- https://master.php.net/note/delete/115656
Reject -- https://master.php.net/note/reject/115656
Search -- https://master.php.net/manage/user-notes.php