You are here

private function XliffFileLoader::utf8ToCharset in Plug 7

Convert a UTF8 string to the specified encoding.

Parameters

string $content String to decode:

string $encoding Target encoding:

Return value

string

1 call to XliffFileLoader::utf8ToCharset()
XliffFileLoader::load in lib/Symfony/translation/Loader/XliffFileLoader.php
@api

File

lib/Symfony/translation/Loader/XliffFileLoader.php, line 97

Class

XliffFileLoader
XliffFileLoader loads translations from XLIFF files.

Namespace

Symfony\Component\Translation\Loader

Code

private function utf8ToCharset($content, $encoding = null) {
  if ('UTF-8' !== $encoding && !empty($encoding)) {
    if (function_exists('mb_convert_encoding')) {
      return mb_convert_encoding($content, $encoding, 'UTF-8');
    }
    if (function_exists('iconv')) {
      return iconv('UTF-8', $encoding, $content);
    }
    throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
  }
  return $content;
}