You are here

protected function FeedsExBase::convertEncoding in Feeds extensible parsers 7.2

Converts a string to UTF-8.

Requires the iconv, GNU recode or mbstring PHP extension.

Parameters

string $data: The string to convert.

string $encoding: The encoding to convert to.

Return value

string The encoded string, or the original string if encoding failed.

See also

drupal_convert_to_utf8()

5 calls to FeedsExBase::convertEncoding()
FeedsExJmesPath::executeContext in src/FeedsExJmesPath.inc
Returns rows to be parsed.
FeedsExJmesPathLines::executeSourceExpression in src/FeedsExJmesPathLines.inc
Executes a single source expression.
FeedsExJsonPath::executeContext in src/FeedsExJsonPath.inc
Returns rows to be parsed.
FeedsExJsonPathLines::executeSourceExpression in src/FeedsExJsonPathLines.inc
Executes a single source expression.
FeedsExXml::convertEncoding in src/FeedsExXml.inc
Converts a string to UTF-8.
1 method overrides FeedsExBase::convertEncoding()
FeedsExXml::convertEncoding in src/FeedsExXml.inc
Converts a string to UTF-8.

File

src/FeedsExBase.inc, line 406
Contains FeedsExBase.

Class

FeedsExBase
The Feeds extensible parser.

Code

protected function convertEncoding($data, $encoding) {
  $php_supported = array(
    'utf-8',
    'us-ascii',
    'ascii',
  );
  if (in_array(strtolower($encoding), $php_supported)) {
    return $data;
  }
  $converted = drupal_convert_to_utf8($data, $encoding);
  if ($converted === FALSE) {
    return $data;
  }
  return $converted;
}