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

Breadcrumb

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

function Scanner::stripBOM

Strips BOM characters from the source and detects source encoding if not given by the user

Parameters

string $source Source:

string $encoding User specified encoding:

1 call to Scanner::stripBOM()
Scanner::__construct in vendor/mck89/peast/lib/Peast/Syntax/Scanner.php
Class constructor

File

vendor/mck89/peast/lib/Peast/Syntax/Scanner.php, line 407

Class

Scanner
Base class for scanners.

Namespace

Peast\Syntax

Code

public function stripBOM(&$source, &$encoding) {
    $boms = array(
        "\xef" => array(
            array(
                "\xbb",
                "\xbf",
            ),
            "UTF-8",
        ),
        "\xfe" => array(
            array(
                "\xff",
            ),
            "UTF-16BE",
        ),
        "\xff" => array(
            array(
                "\xfe",
            ),
            "UTF-16LE",
        ),
    );
    if (!isset($source[0]) || !isset($boms[$source[0]])) {
        return;
    }
    $bom = $boms[$source[0]];
    $l = count($bom[0]);
    for ($i = 0; $i < $l; $i++) {
        if (!isset($source[$i + 1]) || $source[$i + 1] !== $bom[0][$i]) {
            return;
        }
    }
    $source = substr($source, $l + 1);
    if (!$encoding) {
        $encoding = $bom[1];
    }
}

API Navigation

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