private static function EasychartUpdate::parseCSV in Easychart 8.3
Helper function to parse the csv data into an array.
Parameters
$csv_string: The CSV.
string $delimiter: The delimiter.
bool $skip_empty_lines: Whether to skip empty lines or not
bool $trim_fields: Whether to trim fields or not.
Return value
array
1 call to EasychartUpdate::parseCSV()
- EasychartUpdate::updateCSVFromUrl in src/
EasychartUpdate.php - Update the csv data from the url stored in the database.
File
- src/
EasychartUpdate.php, line 64 - Contains \Drupal\easychart\EasychartUpdate
Class
Namespace
Drupal\easychartCode
private static function parseCSV($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);
}