Skip to content

Instantly share code, notes, and snippets.

@osde8info
Forked from johanmeiring/gist:2894568
Last active July 12, 2023 19:24
Show Gist options
  • Save osde8info/ad9b9156e0fb2b6f0942 to your computer and use it in GitHub Desktop.
Save osde8info/ad9b9156e0fb2b6f0942 to your computer and use it in GitHub Desktop.
str_putcsv for php
<?php
/* From: http://www.php.net/manual/en/function.str-getcsv.php#88773 and http://www.php.net/manual/en/function.str-getcsv.php#91170 */
if(!function_exists('str_putcsv'))
{
function str_putcsv($input, $delimiter = ',', $enclosure = '"')
{
$csv = fopen('php://temp','r+');
fputcsv($csv, $input);
rewind($csv);
$output = stream_get_contents($csv);
fclose($csv);
return $output;
}
}
@lwcorp
Copy link

lwcorp commented Jul 12, 2023

What are your thoughts about the original version that has $data = fgets($fp); instead of $output = stream_get_contents($csv);? And any idea why it got -1 points while it seems to work well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment