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?
asked Jul 27, 2013 at 8:36
Dr.Kameleon
22.8k21 gold badges124 silver badges241 bronze badges
-
1there 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 alsoDevZer0– DevZer02013年07月27日 08:42:03 +00:00Commented 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 headerOrangepill– Orangepill2013年07月27日 08:45:19 +00:00Commented 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-csvuser1603136– user16031362013年07月28日 23:06:18 +00:00Commented Jul 28, 2013 at 23:06
1 Answer 1
Have a look at this fputcsv to variable
Sign up to request clarification or add additional context in comments.
Comments
lang-php