public static Unicode::encodingFromBOM($data)
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
- core/lib/Drupal/Component/Utility/Unicode.php, line 191
Class
- Unicode
- Provides Unicode-related conversions and operations.
Namespace
Drupal\Component\Utility
Code
public static function encodingFromBOM($data) {
static $bomMap = array(
"\xEF\xBB\xBF" => 'UTF-8',
"\xFE\xFF" => 'UTF-16BE',
"\xFF\xFE" => 'UTF-16LE',
"\x00\x00\xFE\xFF" => 'UTF-32BE',
"\xFF\xFE\x00\x00" => 'UTF-32LE',
"\x2B\x2F\x76\x38" => 'UTF-7',
"\x2B\x2F\x76\x39" => 'UTF-7',
"\x2B\x2F\x76\x2B" => 'UTF-7',
"\x2B\x2F\x76\x2F" => 'UTF-7',
"\x2B\x2F\x76\x38\x2D" => 'UTF-7',
);
foreach ($bomMap as $bom => $encoding) {
if (strpos($data, $bom) === 0) {
return $encoding;
}
}
return FALSE;
}
Please login to continue.