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

Breadcrumb

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

function Iconv::iconv

7 calls to Iconv::iconv()
Iconv::iconv_mime_decode in vendor/symfony/polyfill-iconv/Iconv.php
Iconv::iconv_mime_encode in vendor/symfony/polyfill-iconv/Iconv.php
Iconv::iconv_strpos in vendor/symfony/polyfill-iconv/Iconv.php
Iconv::iconv_strrpos in vendor/symfony/polyfill-iconv/Iconv.php
Iconv::iconv_substr in vendor/symfony/polyfill-iconv/Iconv.php

... See full list

File

vendor/symfony/polyfill-iconv/Iconv.php, line 128

Class

Iconv
iconv implementation in pure PHP, UTF-8 centric.

Namespace

Symfony\Polyfill\Iconv

Code

public static function iconv($inCharset, $outCharset, $str) {
    $str = (string) $str;
    if ('' === $str) {
        return '';
    }
    // Prepare for //IGNORE and //TRANSLIT
    $translit = $ignore = '';
    $outCharset = strtolower($outCharset);
    $inCharset = strtolower($inCharset);
    if ('' === $outCharset) {
        $outCharset = 'iso-8859-1';
    }
    if ('' === $inCharset) {
        $inCharset = 'iso-8859-1';
    }
    do {
        $loop = false;
        if ('//translit' === substr($outCharset, -10)) {
            $loop = $translit = true;
            $outCharset = substr($outCharset, 0, -10);
        }
        if ('//ignore' === substr($outCharset, -8)) {
            $loop = $ignore = true;
            $outCharset = substr($outCharset, 0, -8);
        }
    } while ($loop);
    do {
        $loop = false;
        if ('//translit' === substr($inCharset, -10)) {
            $loop = true;
            $inCharset = substr($inCharset, 0, -10);
        }
        if ('//ignore' === substr($inCharset, -8)) {
            $loop = true;
            $inCharset = substr($inCharset, 0, -8);
        }
    } while ($loop);
    if (isset(self::$alias[$inCharset])) {
        $inCharset = self::$alias[$inCharset];
    }
    if (isset(self::$alias[$outCharset])) {
        $outCharset = self::$alias[$outCharset];
    }
    // Load charset maps
    if ('utf-8' !== $inCharset && !self::loadMap('from.', $inCharset, $inMap) || 'utf-8' !== $outCharset && !self::loadMap('to.', $outCharset, $outMap)) {
        trigger_error(sprintf(self::ERROR_WRONG_CHARSET, $inCharset, $outCharset));
        return false;
    }
    if ('utf-8' !== $inCharset) {
        // Convert input to UTF-8
        $result = '';
        if (self::mapToUtf8($result, $inMap, $str, $ignore)) {
            $str = $result;
        }
        else {
            $str = false;
        }
        self::$isValidUtf8 = true;
    }
    else {
        self::$isValidUtf8 = preg_match('//u', $str);
        if (!self::$isValidUtf8 && !$ignore) {
            trigger_error(self::ERROR_ILLEGAL_CHARACTER);
            return false;
        }
        if ('utf-8' === $outCharset) {
            // UTF-8 validation
            $str = self::utf8ToUtf8($str, $ignore);
        }
    }
    if ('utf-8' !== $outCharset && false !== $str) {
        // Convert output to UTF-8
        $result = '';
        if (self::mapFromUtf8($result, $outMap, $str, $ignore, $translit)) {
            return $result;
        }
        return false;
    }
    return $str;
}

API Navigation

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