note 100579 deleted from function.str-getcsv by cmb
| From: | cmb@php.net | Date: | Sun, 09 Feb 2020 08:22:58 +0000 |
| Subject: | note 100579 deleted from function.str-getcsv by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214057@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
If your version of PHP doesn't have
str_getcsv and you don't need custom
$escape or $eol values, try this:
<?php if (!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter=',', $enclosure='"', $escape=null,
$eol=null) {
$temp=fopen("php://memory", "rw");
fwrite($temp, $input);
fseek($temp, 0);
$r = array();
while (($data = fgetcsv($temp, 4096, $delimiter, $enclosure)) !== false) {
$r[] = $data;
}
fclose($temp);
return $r;
}
} ?>
[EDIT BY danbrown AT php DOT net: Contains a bugfix provided by (depely AT IAMNOTABOT
prestaconcept.net) on 04-MAR-2011 with the following note: "The previous anonymous function
only read the first line".]