Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Component/Utility/Unicode.php \Drupal\Component\Utility\Unicode::encodingFromBOM()
  2. 9 core/lib/Drupal/Component/Utility/Unicode.php \Drupal\Component\Utility\Unicode::encodingFromBOM()

Decodes UTF byte-order mark (BOM) to the encoding 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.

1 call to Unicode::encodingFromBOM()
CssOptimizer::loadFile in core/lib/Drupal/Core/Asset/CssOptimizer.php
Loads the stylesheet and resolves all @import commands.

File

core/lib/Drupal/Component/Utility/Unicode.php, line 151

Class

Unicode
Provides Unicode-related conversions and operations.

Namespace

Drupal\Component\Utility

Code

public static function encodingFromBOM($data) {
  static $bomMap = [
    "" => '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 (str_starts_with($data, $bom)) {
      return $encoding;
    }
  }
  return FALSE;
}