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?

3
  • 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 Commented Jul 27, 2013 at 8: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 Commented Jul 27, 2013 at 8:45
  • Check Paul's answer, I use this function and it works perfrecly : stackoverflow.com/questions/3933668/convert-array-into-csv Commented Jul 28, 2013 at 23:06

1 Answer 1

1

Have a look at this fputcsv to variable

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.