mirror of
https://github.com/moodle/moodle.git
synced 2025-04-24 18:04:43 +02:00
MDL-72342 groups: Use get_columns() to handle BOM in CSV
Ensuring that BOM was properly removed from input CSV file by using get_columns() instead of parsing the raw data.
This commit is contained in:
parent
1464843a25
commit
b25e1738a6
@ -61,8 +61,6 @@ if ($importform->is_cancelled()) {
|
||||
$text = $importform->get_file_content('userfile');
|
||||
$text = preg_replace('!\r\n?!', "\n", $text);
|
||||
|
||||
$rawlines = explode("\n", $text);
|
||||
|
||||
require_once($CFG->libdir . '/csvlib.class.php');
|
||||
$importid = csv_import_reader::get_new_iid('groupimport');
|
||||
$csvimport = new csv_import_reader($importid, 'groupimport');
|
||||
@ -95,7 +93,9 @@ if ($importform->is_cancelled()) {
|
||||
);
|
||||
|
||||
// --- get header (field names) ---
|
||||
$header = explode($csvimport::get_delimiter($delimiter), array_shift($rawlines));
|
||||
// Using get_columns() ensures the Byte Order Mark is removed.
|
||||
$header = $csvimport->get_columns();
|
||||
|
||||
// check for valid field names
|
||||
foreach ($header as $i => $h) {
|
||||
$h = trim($h); $header[$i] = $h; // remove whitespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user