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 = self::iconvAvailable();
        }
        if ($iconv && !$config->get('Test.ForceNoIconv')) {
            // unaffected by bugs, since UTF-8 support all characters
            $str = self::unsafeIconv($encoding, 'utf-8//IGNORE', $str);
            if ($str === false) {
                // $encoding is not a valid encoding
                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, self::testEncodingSupportsASCII($encoding));
            return $str;
        } elseif ($encoding === 'iso-8859-1') {
            $str = utf8_encode($str);
            return $str;
        }
        $bug = HTMLPurifier_Encoder::testIconvTruncateBug();
        if ($bug == self::ICONV_OK) {
            trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
        } else {
            trigger_error(
                'You have a buggy version of iconv, see https://bugs.php.net/bug.php?id=48147 ' .
                'and http://sourceware.org/bugzilla/show_bug.cgi?id=13541',
                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 = self::iconvAvailable();
        }
        if ($iconv && !$config->get('Test.ForceNoIconv')) {
            // unaffected by bugs, since UTF-8 support all characters
            $str = self::unsafeIconv($encoding, 'utf-8//IGNORE', $str);
            if ($str === false) {
                // $encoding is not a valid encoding
                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, self::testEncodingSupportsASCII($encoding));
            return $str;
        } elseif ($encoding === 'iso-8859-1') {
            $str = utf8_encode($str);
            return $str;
        }
        $bug = HTMLPurifier_Encoder::testIconvTruncateBug();
        if ($bug == self::ICONV_OK) {
            trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
        } else {
            trigger_error(
                'You have a buggy version of iconv, see https://bugs.php.net/bug.php?id=48147 ' .
                'and http://sourceware.org/bugzilla/show_bug.cgi?id=13541',
                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 = self :: iconvAvailable ( ) ; } if ( $ iconv && ! $ config -> get ( 'Test.ForceNoIconv' ) ) { // unaffected by bugs, since UTF-8 support all characters
 $ str = self :: unsafeIconv ( $ encoding , 'utf-8//IGNORE' , $ str ) ; if ( $ str === false ) { // $encoding is not a valid encoding
 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 , self :: testEncodingSupportsASCII ( $ encoding ) ) ; return $ str ; } elseif ( $ encoding === 'iso-8859-1' ) { $ str = utf8_encode ( $ str ) ; return $ str ; } $ bug = HTMLPurifier_Encoder :: testIconvTruncateBug ( ) ; if ( $ bug == self :: ICONV_OK ) { trigger_error ( 'Encoding not supported, please install iconv' , E_USER_ERROR ) ; } else { trigger_error ( 'You have a buggy version of iconv, see https://bugs.php.net/bug.php?id=48147 ' . 'and http://sourceware.org/bugzilla/show_bug.cgi?id=13541' , E_USER_ERROR ) ; } }
Convert a string to UTF-8 based on configuration.
@param string $str The string to convert
@param HTMLPurifier_Config $config
@param HTMLPurifier_Context $context
@return string
Convert a string to UTF - 8 based on configuration .