-
-
Save pmatseykanets/2bed81c01afa90c6e48c to your computer and use it in GitHub Desktop.
Format line as CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Forked from https://gist.github.com/johanmeiring/2894568 */ | |
if (! function_exists('str_putcsv')) | |
{ | |
function str_putcsv($input, $delimiter = ',', $enclosure = '"') | |
{ | |
// Open a memory "file" for read/write | |
$memory = fopen('php://temp', 'r+'); | |
// Write the $input array to the "file" using fputcsv() | |
$length = fputcsv($memory, $input, $delimiter, $enclosure); | |
// Rewind the "file" so we can read what we just wrote | |
rewind($memory); | |
// Read the entire line, except for a new line charater into a variable | |
$csv = fread($memory, $length-1); | |
// Close the "file" | |
fclose($memory); | |
// Return the formatted string | |
return $csv; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment