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

Breadcrumb

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

function Mbstring::mb_detect_encoding

2 calls to Mbstring::mb_detect_encoding()
Mbstring::mb_check_encoding in vendor/symfony/polyfill-mbstring/Mbstring.php
Mbstring::mb_convert_encoding in vendor/symfony/polyfill-mbstring/Mbstring.php

File

vendor/symfony/polyfill-mbstring/Mbstring.php, line 450

Class

Mbstring
Partial mbstring implementation in PHP, iconv based, UTF-8 centric.

Namespace

Symfony\Polyfill\Mbstring

Code

public static function mb_detect_encoding($str, $encodingList = null, $strict = false) {
    if (null === $encodingList) {
        $encodingList = self::$encodingList;
    }
    else {
        if (!\is_array($encodingList)) {
            $encodingList = array_map('trim', explode(',', $encodingList));
        }
        $encodingList = array_map('strtoupper', $encodingList);
    }
    foreach ($encodingList as $enc) {
        switch ($enc) {
            case 'ASCII':
                if (!preg_match('/[\\x80-\\xFF]/', $str)) {
                    return $enc;
                }
                break;
            case 'UTF8':
            case 'UTF-8':
                if (preg_match('//u', $str)) {
                    return 'UTF-8';
                }
                break;
            default:
                if (0 === strncmp($enc, 'ISO-8859-', 9)) {
                    return $enc;
                }
        }
    }
    return false;
}

API Navigation

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