Re: Array to csv or excel in php

From: Date: Mon, 19 Apr 2010 15:00:45 +0000
Subject: Re: Array to csv or excel in php
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-304218@lists.php.net to get a copy of this message
On Mon, Apr 19, 2010 at 9:45 AM, Manolis Vlachakis <vlachakis.manolis@gmail.com> wrote: > hallo there everyone.. > i got an array from my database > Help with Code Tags<›¢:Ÿ°Øf~ä º > £�http://www.daniweb.com/forums/misc-explaincode.html?TB_iframe=true&height=400&width=680> > *PHP Syntax* (Toggle Plain > Text<http://www.daniweb.com/forums/post1194347..html#> > ) > > >   1. $save=split("[|;]",$listOfItems); > > > and what i want i s after making some changes to the attributes on the array > above to export them on an csv or excel format > but directly as a message to the browser .. > i dont want it to be saved on the server ... > what i cant understand from the examples i found on the net .. > is how to handle the files and which are created cause > i just have the array in a php file nothing more... > > > another thing i have in mind is to export from the ldap server the files > directly but seems to me as the wrong way to do it > > thanks > Often when outputting csv, I usually do something like this: <?php $fp = fopen('php://output', 'w') or die('Could not open stream'); foreach ($data as $row) { // Assumes that $row will be an array. // Manipulate the data in $row if necessary. fputcsv($fp, $row); } ?> So far, it has worked pretty well and is much faster than any other way I have found to output the CSV data by iterating through the arrays manually. Andrew

« previous php.general (#304218) next »