M.O.S. Studios Posted yesterday at 03:23 AM Share Posted yesterday at 03:23 AM Hey everyone, I am trying to take information from a DB and convert it into a string that has CSV values. some of the values have commas and double quotes, which messes up the end product. is there a way to escape the string so it is rfc 4180 compliant? I don’t want to create a file. I know I can use str_putcsv along with php://temp; but ideally I wouldn’t do that. Mostly because my shared hosting has issues php://temp thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/326729-string-into-csv/ Share on other sites More sharing options...
gizmola Posted 18 hours ago Share Posted 18 hours ago I'd suggest you try to use php://output directly. $stdout = fopen('php://output','w'); foreach($rows as $row) { fputcsv($stdout, $row); } fflush($stdout); If for some reason this doesn't work (or work reliably) with your host, then I'd suggest writing the data to a file with a temporary name you create using some random input and something like sha1, and then open that file and send it back to the user, but sending it directly to output is a standard solution for this type of requirement. Quote Link to comment https://forums.phpfreaks.com/topic/326729-string-into-csv/#findComment-1649198 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.