PHP 8.5.0 Alpha 1 available for testing

Voting

: two plus one?
(Example: nine)

The Note You're Voting On

mikhail dot galanin at yahoo dot com
7 years ago
Sometimes it's useful to get CSV line as string. I.e. to store it somewhere, not in on a filesystem.

<?php
function csvstr(array $fields) : string
{
$f = fopen('php://memory', 'r+');
if (
fputcsv($f, $fields) === false) {
return
false;
}
rewind($f);
$csv_line = stream_get_contents($f);
return
rtrim($csv_line);
}
?>

<< Back to user notes page

To Top