public static function Unicode::convertToUtf8 in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Component/Utility/Unicode.php \Drupal\Component\Utility\Unicode::convertToUtf8()
Converts data to UTF-8.
Requires the iconv, GNU recode or mbstring PHP extension.
Parameters
string $data: The data to be converted.
string $encoding: The encoding that the data is in.
Return value
string|bool Converted data or FALSE.
5 calls to Unicode::convertToUtf8()
- CssOptimizer::loadFile in core/
lib/ Drupal/ Core/ Asset/ CssOptimizer.php - Loads the stylesheet and resolves all @import commands.
- drupal_xml_parser_create in core/
includes/ unicode.inc - Prepares a new XML parser.
- JsOptimizer::optimize in core/
lib/ Drupal/ Core/ Asset/ JsOptimizer.php - Optimizes an asset.
- Unicode::mimeHeaderDecode in core/
lib/ Drupal/ Component/ Utility/ Unicode.php - Decodes MIME/HTTP encoded header values.
- UnicodeTest::testConvertToUtf8 in core/
tests/ Drupal/ Tests/ Component/ Utility/ UnicodeTest.php - Tests UTF-8 conversion.
File
- core/
lib/ Drupal/ Component/ Utility/ Unicode.php, line 231 - Contains \Drupal\Component\Utility\Unicode.
Class
- Unicode
- Provides Unicode-related conversions and operations.
Namespace
Drupal\Component\UtilityCode
public static function convertToUtf8($data, $encoding) {
if (function_exists('iconv')) {
return @iconv($encoding, 'utf-8', $data);
}
elseif (function_exists('mb_convert_encoding')) {
return @mb_convert_encoding($data, 'utf-8', $encoding);
}
elseif (function_exists('recode_string')) {
return @recode_string($encoding . '..utf-8', $data);
}
// Cannot convert.
return FALSE;
}