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

Breadcrumb

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

function Mbstring::mb_internal_trim

3 calls to Mbstring::mb_internal_trim()
Mbstring::mb_ltrim in vendor/symfony/polyfill-mbstring/Mbstring.php
Mbstring::mb_rtrim in vendor/symfony/polyfill-mbstring/Mbstring.php
Mbstring::mb_trim in vendor/symfony/polyfill-mbstring/Mbstring.php

File

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

Class

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

Namespace

Symfony\Polyfill\Mbstring

Code

private static function mb_internal_trim(string $regex, string $string, ?string $characters, ?string $encoding, string $function) : string {
    if (null === $encoding) {
        $encoding = self::mb_internal_encoding();
    }
    else {
        self::assertEncoding($encoding, $function . '(): Argument #3 ($encoding) must be a valid encoding, "%s" given');
    }
    if ('' === $characters) {
        return null === $encoding ? $string : self::mb_convert_encoding($string, $encoding);
    }
    if ('UTF-8' === $encoding) {
        $encoding = null;
        if (!preg_match('//u', $string)) {
            $string = @iconv('UTF-8', 'UTF-8//IGNORE', $string);
        }
        if (null !== $characters && !preg_match('//u', $characters)) {
            $characters = @iconv('UTF-8', 'UTF-8//IGNORE', $characters);
        }
    }
    else {
        $string = iconv($encoding, 'UTF-8//IGNORE', $string);
        if (null !== $characters) {
            $characters = iconv($encoding, 'UTF-8//IGNORE', $characters);
        }
    }
    if (null === $characters) {
        $characters = "\\0 \f\n\r\t\v             

   …᠎";
    }
    else {
        $characters = preg_quote($characters);
    }
    $string = preg_replace(sprintf($regex, $characters), '', $string);
    if (null === $encoding) {
        return $string;
    }
    return iconv('UTF-8', $encoding . '//IGNORE', $string);
}

API Navigation

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