public static function Unicode::encodingFromBOM in Service Container 7.2
Same name and namespace in other branches
- 7 lib/Drupal/Component/Utility/Unicode.php \Drupal\Component\Utility\Unicode::encodingFromBOM()
Decodes UTF byte-order mark (BOM) into the encoding's name.
Parameters
string $data: The data possibly containing a BOM. This can be the entire contents of a file, or just a fragment containing at least the first five bytes.
Return value
string|bool The name of the encoding, or FALSE if no byte order mark was present.
File
- lib/
Drupal/ Component/ Utility/ Unicode.php, line 196 - Contains \Drupal\Component\Utility\Unicode.
Class
- Unicode
- Provides Unicode-related conversions and operations.
Namespace
Drupal\Component\UtilityCode
public static function encodingFromBOM($data) {
static $bomMap = array(
"" => 'UTF-8',
"" => 'UTF-16BE',
"" => 'UTF-16LE',
"" => 'UTF-32BE',
"" => 'UTF-32LE',
"+/v8" => 'UTF-7',
"+/v9" => 'UTF-7',
"+/v+" => 'UTF-7',
"+/v/" => 'UTF-7',
"+/v8-" => 'UTF-7',
);
foreach ($bomMap as $bom => $encoding) {
if (strpos($data, $bom) === 0) {
return $encoding;
}
}
return FALSE;
}