note 103854 deleted from function.str-getcsv by danbrown
| From: | danbrown@php.net | Date: | Fri, 06 May 2011 18:32:07 +0000 |
| Subject: | note 103854 deleted from function.str-getcsv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179507@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
An addition to Anonymous note on 25-Oct-2010 07:25, is to make it so you can parse a string for
UNIX/Win/Mac since the native str_getcsv will not honor auto_detect_line_endings:
function parse_csv_str($input, $delimiter=',', $enclosure='"',
$escape=null, $eol=null) {
// make mac/doc/unix friendly
ini_set('auto_detect_line_endings', TRUE);
$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;
}