1

OK, this is what I need :

I have an array with data and I need to convert it to a CSV string which can then be passed to CodeIgniter's force_download download function.

I know of PHP's built-in function fputcsv, but I now need to store the whole thing to a string (preferably without first having to save it to a file). And, preferably without having to write any custom function for escaping characters, etc.

So, how can this be done? Any ideas?

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
  • 1
    there is many ways to do this, you can use a physical file pointer to putcsv and then once completed read it out as a string and unlink the file. I am also quite sure you can ob_start() and fputcsv to php://stdout and grab the output that way also – DevZer0 Jul 27 '13 at 08:42
  • you dont even have to ob it. just grab the php://output and fputs away. you only need to ob if you want to send a content-length header – Orangepill Jul 27 '13 at 08:45
  • Check Paul's answer, I use this function and it works perfrecly : http://stackoverflow.com/questions/3933668/convert-array-into-csv –  Jul 28 '13 at 23:06

1 Answers1

1

Have a look at this fputcsv to variable

Ashneil Roy
  • 154
  • 5