You are here

function tablefield_convert_encoding in TableField 7.3

Same name and namespace in other branches
  1. 7.2 tablefield.module \tablefield_convert_encoding()

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_convert_encoding()
tablefield_import_csv in ./tablefield.module
Helper function to import data from a CSV file.

File

./tablefield.module, line 2117
Provides a set of fields that can be used to store tabular data with a node.

Code

function tablefield_convert_encoding($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 = drupal_convert_to_utf8($data, $encoding)) {
    return $encoded_data;
  }

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