Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Unicode.php

function 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.

2 calls to Unicode::encodingFromBOM()
CssOptimizer::loadFile in core/lib/Drupal/Core/Asset/CssOptimizer.php
Loads the stylesheet and resolves all @import commands.
JsOptimizer::optimize in core/lib/Drupal/Core/Asset/JsOptimizer.php
Optimizes an asset.

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',
        "\xfe\xff" => 'UTF-16BE',
        "\xff\xfe" => 'UTF-16LE',
        "\x00\x00\xfe\xff" => 'UTF-32BE',
        "\xff\xfe\x00\x00" => '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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal