note 91170 added to function.str-getcsv
| From: | Ulf at osu1 dot php dot net | Date: | Thu, 28 May 2009 13:24:09 +0000 |
| Subject: | note 91170 added to function.str-getcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156109@lists.php.net to get a copy of this message | ||
As Dave's function also had the problem with only one line being returned here's a
slightly changed version:
<?php
function str_putcsv($input, $delimiter = ',', $enclosure = '"') {
// Open a memory "file" for read/write...
$fp = fopen('php://temp', 'r+');
// ... write the $input array to the "file" using fputcsv()...
fputcsv($fp, $input, $delimiter, $enclosure);
// ... rewind the "file" so we can read what we just wrote...
rewind($fp);
// ... read the entire line into a variable...
$data = fread($fp, 1048576); // [changed]
// ... close the "file"...
fclose($fp);
// ... and return the $data to the caller, with the trailing newline from fgets() removed.
return rtrim( $data, "\n" );
}
?>
It assumes that one line won't exceed 1Mb of data. That should be more than enough.
----
Server IP: 212.124.37.9
Probable Submitter: 85.183.23.96
----
Manual Page -- http://www.php.net/manual/en/function.str-getcsv.php
Edit -- https://master.php.net/note/edit/91170
Del: integrated -- https://master.php.net/note/delete/91170/integrated
Del: useless -- https://master.php.net/note/delete/91170/useless
Del: bad code -- https://master.php.net/note/delete/91170/bad+code
Del: spam -- https://master.php.net/note/delete/91170/spam
Del: non-english -- https://master.php.net/note/delete/91170/non-english
Del: in docs -- https://master.php.net/note/delete/91170/in+docs
Del: other reasons-- https://master.php.net/note/delete/91170
Reject -- https://master.php.net/note/reject/91170
Search -- https://master.php.net/manage/user-notes.php