Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/326729-string-into-csv/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/326729-string-into-csv/#findComment-1649198
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.