You are here

protected static function Tablefield::convertEncoding in TableField 8.2

Helper function to detect and convert strings not in UTF-8 to UTF-8.

Parameters

string $data: The string which needs converting.

string $encoding: The encoding of the CSV file.

Return value

string UTF encoded string.

1 call to Tablefield::convertEncoding()
Tablefield::importCsv in src/Element/Tablefield.php
Helper function to import data from a CSV file.

File

src/Element/Tablefield.php, line 379

Class

Tablefield
Provides a form element for tabular data.

Namespace

Drupal\tablefield\Element

Code

protected static function convertEncoding($data, $encoding) {

  // Converting UTF-8 to UTF-8 will not work.
  if ($encoding == 'UTF-8') {
    return $data;
  }

  // Try convert the data to UTF-8.
  if ($encoded_data = Unicode::convertToUtf8($data, $encoding)) {
    return $encoded_data;
  }

  // Fallback on the input data.
  return $data;
}