note 100579 modified in function.str-getcsv by danbrown
| From: | danbrown@php.net | Date: | Fri, 04 Mar 2011 14:50:15 +0000 |
| Subject: | note 100579 modified in function.str-getcsv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177558@lists.php.net to get a copy of this message | ||
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".]
--was--
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=fgetcsv($temp, 4096, $delimiter, $enclosure);
fclose($temp);
return $r;
}
} ?>
http://php.net/manual/en/function.str-getcsv.php