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

Breadcrumb

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

function Mbstring::mb_convert_encoding

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

File

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

Class

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

Namespace

Symfony\Polyfill\Mbstring

Code

public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null) {
    if (\is_array($s)) {
        $r = [];
        foreach ($s as $str) {
            $r[] = self::mb_convert_encoding($str, $toEncoding, $fromEncoding);
        }
        return $r;
    }
    if (\is_array($fromEncoding) || null !== $fromEncoding && false !== strpos($fromEncoding, ',')) {
        $fromEncoding = self::mb_detect_encoding($s, $fromEncoding);
    }
    else {
        $fromEncoding = self::getEncoding($fromEncoding);
    }
    $toEncoding = self::getEncoding($toEncoding);
    if ('BASE64' === $fromEncoding) {
        $s = base64_decode($s);
        $fromEncoding = $toEncoding;
    }
    if ('BASE64' === $toEncoding) {
        return base64_encode($s);
    }
    if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) {
        if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
            $fromEncoding = 'Windows-1252';
        }
        if ('UTF-8' !== $fromEncoding) {
            $s = iconv($fromEncoding, 'UTF-8//IGNORE', $s);
        }
        return preg_replace_callback('/[\\x80-\\xFF]+/', [
            __CLASS__,
            'html_encoding_callback',
        ], $s);
    }
    if ('HTML-ENTITIES' === $fromEncoding) {
        $s = html_entity_decode($s, \ENT_COMPAT, 'UTF-8');
        $fromEncoding = 'UTF-8';
    }
    return iconv($fromEncoding, $toEncoding . '//IGNORE', $s);
}

API Navigation

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