function _parse_csv in Easychart 7.3
Helper function to parse the csv data into an array.
1 call to _parse_csv()
- _easychart_update_csv_from_url in ./
easychart.helpers.inc - Update the csv data from the url stored in the database.
File
- ./
easychart.helpers.inc, line 68 - Easychart helpers.
Code
function _parse_csv($csv_string, $delimiter = ",", $skip_empty_lines = true, $trim_fields = true) {
$enc = preg_replace('/(?<!")""/', '!!Q!!', $csv_string);
$enc = preg_replace_callback('/"(.*?)"/s', function ($field) {
return urlencode(utf8_encode($field[1]));
}, $enc);
$lines = preg_split($skip_empty_lines ? $trim_fields ? '/( *\\R)+/s' : '/\\R+/s' : '/\\R/s', $enc);
return array_map(function ($line) use ($delimiter, $trim_fields) {
$fields = $trim_fields ? array_map('trim', explode($delimiter, $line)) : explode($delimiter, $line);
return array_map(function ($field) {
return str_replace('!!Q!!', '"', utf8_decode(urldecode($field)));
}, $fields);
}, $lines);
}