thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/Encoder.php
public static function convertToUTF8($str, $config, $context) {
        $encoding = $config->get('Core.Encoding');
        if ($encoding === 'utf-8') return $str;
        static $iconv = null;
        if ($iconv === null) $iconv = function_exists('iconv');
        set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
        if ($iconv && !$config->get('Test.ForceNoIconv')) {
            $str = iconv($encoding, 'utf-8//IGNORE', $str);
            if ($str === false) {
                // $encoding is not a valid encoding
                restore_error_handler();
                trigger_error('Invalid encoding ' . $encoding, E_USER_ERROR);
                return '';
            }
            // If the string is bjorked by Shift_JIS or a similar encoding
            // that doesn't support all of ASCII, convert the naughty
            // characters to their true byte-wise ASCII/UTF-8 equivalents.
            $str = strtr($str, HTMLPurifier_Encoder::testEncodingSupportsASCII($encoding));
            restore_error_handler();
            return $str;
        } elseif ($encoding === 'iso-8859-1') {
            $str = utf8_encode($str);
            restore_error_handler();
            return $str;
        }
        trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
    }
public static function convertToUTF8($str, $config, $context) {
        $encoding = $config->get('Core.Encoding');
        if ($encoding === 'utf-8') return $str;
        static $iconv = null;
        if ($iconv === null) $iconv = function_exists('iconv');
        set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
        if ($iconv && !$config->get('Test.ForceNoIconv')) {
            $str = iconv($encoding, 'utf-8//IGNORE', $str);
            if ($str === false) {
                // $encoding is not a valid encoding
                restore_error_handler();
                trigger_error('Invalid encoding ' . $encoding, E_USER_ERROR);
                return '';
            }
            // If the string is bjorked by Shift_JIS or a similar encoding
            // that doesn't support all of ASCII, convert the naughty
            // characters to their true byte-wise ASCII/UTF-8 equivalents.
            $str = strtr($str, HTMLPurifier_Encoder::testEncodingSupportsASCII($encoding));
            restore_error_handler();
            return $str;
        } elseif ($encoding === 'iso-8859-1') {
            $str = utf8_encode($str);
            restore_error_handler();
            return $str;
        }
        trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
    }
public static function convertToUTF8 ( $ str , $ config , $ context ) { $ encoding = $ config -> get ( 'Core.Encoding' ) ; if ( $ encoding === 'utf-8' ) return $ str ; static $ iconv = null ; if ( $ iconv === null ) $ iconv = function_exists ( 'iconv' ) ; set_error_handler ( array ( 'HTMLPurifier_Encoder' , 'muteErrorHandler' ) ) ; if ( $ iconv && ! $ config -> get ( 'Test.ForceNoIconv' ) ) { $ str = iconv ( $ encoding , 'utf-8//IGNORE' , $ str ) ; if ( $ str === false ) { // $encoding is not a valid encoding restore_error_handler ( ) ; trigger_error ( 'Invalid encoding ' . $ encoding , E_USER_ERROR ) ; return '' ; } // If the string is bjorked by Shift_JIS or a similar encoding // that doesn't support all of ASCII, convert the naughty // characters to their true byte-wise ASCII/UTF-8 equivalents. $ str = strtr ( $ str , HTMLPurifier_Encoder :: testEncodingSupportsASCII ( $ encoding ) ) ; restore_error_handler ( ) ; return $ str ; } elseif ( $ encoding === 'iso-8859-1' ) { $ str = utf8_encode ( $ str ) ; restore_error_handler ( ) ; return $ str ; } trigger_error ( 'Encoding not supported, please install iconv' , E_USER_ERROR ) ; }
Converts a string to UTF-8 based on configuration.
Converts a string to UTF - 8 based on configuration .