Try to convert upper unicode characters to plain ascii,
the returned string may contain unconverted unicode characters.

@param string $text input string
@param string $charset encoding of the text
@return string converted ascii string
12834
public static function specialtoascii($text, $charset='utf-8') {
        $charset = self::parse_charset($charset);
        $oldlevel = error_reporting(E_PARSE);
        $result = self::typo3()->specCharsToASCII($charset, (string)$text);
        error_reporting($oldlevel);
        return $result;
    }
561811
public static function encode($encodingLabel, $text)
    {
        $encodingLabel = self::normalizeEncoding($encodingLabel);
        if ($encodingLabel == 'ISO-8859-1')
            return self::toWin1252($text);
        return self::toUTF8($text);
    }
272100
private function getNormalizedCharset($charset)
    {
        $upper = null;
        if (is_array($charset)) {
            $upper = array_map('strtoupper', $charset);
        } else {
            $upper = strtoupper($charset);
        }
        return preg_replace('/[^A-Z0-9]+/', '', $upper);
    }
472919
public function charset($charset = null)
    {
        if (!func_num_args()) {
            return $this->_stream->charset();
        }
        $this->_stream->charset($charset);
        return $this;
    }
854026
public function charset($charset = null)
    {
        if (!func_num_args()) {
            list($mime, $charset) = $this->_inspectContentType();
            return $this->_charset = $charset;
        }
        $this->_charset = $charset ? strtoupper($charset) : null;
        $this->_updateContentType();
        return $this;
    }
894420
public function text($text)
    {
        if (is_string($text) || settype($text, 'string') !== false) {
            return parent::text($this->encodeString($text));
        }
        throw new \InvalidArgumentException(get_class($this) . ':text - Cannot cast passed value to string (did you forget to define a __toString on your object?)');
    }
1254896
public static function convertTagsToRtf($text, $charset)
    {
        $search = array(
            // bold
            '|<STRONG\s*>(.*?)</STRONG\s*>|smi',
            '|<B\s*>(.*?)</B\s*>|smi',
            // italic
            '|<EM\s*>(.*?)</EM\s*>|smi',
            '|<I\s*>(.*?)</I\s*>|smi',
            // underline
            '|<U\s*>(.*?)</U\s*>|smi',
            // break
            '|<BR\s*(/)?\s*>|smi',
            '|<LINE\s*(/)?\s*>|smi',
            // horizontal rule
            '|<HR\s*(/)?\s*>|smi',
            '|<CHDATE\s*(/)?\s*>|smi',
            '|<CHDPL\s*(/)?\s*>|smi',
            '|<CHDPA\s*(/)?\s*>|smi',
            '|<CHTIME\s*(/)?\s*>|smi',
            '|<CHPGN\s*(/)?\s*>|smi',
            // tab
            '|<TAB\s*(/)?\s*>|smi',
            // bullet
            '|<BULLET\s*(/)?\s*>|smi',
            '|<PAGENUM\s*(/)?\s*>|smi',
            '|<PAGETOTAL\s*(/)?\s*>|smi',
            '|<SECTNUM\s*(/)?\s*>|smi',
            '|<SUP\s*>(.*?)</SUP\s*>|smi',
            '|<SUB\s*>(.*?)</SUB\s*>|smi',
//            '|<PAGE\s*(/)?\s*>|smi',
//            '|<SECT\s*(/)?\s*>|smi'
        );

        $replace = array(
            // bold
            '\b \1\b0 ',
            '\b \1\b0 ',
            // italic
            '\i \1\i0 ',
            '\i \1\i0 ',
            // underline
            '\ul \1\ul0 ',
            // break
            '\line ',
            '\line ',
            // horizontal rule
            '{\pard \brdrb \brdrs \brdrw10 \brsp20 \par}',
            '\chdate ',
            '\chdpl ',
            '\chdpa ',
            '\chtime ',
            '\chpgn ',
            // tab
            '\tab ',
            // bullet
            '\bullet ',
            '\chpgn ',
            '{\field {\*\fldinst {NUMPAGES }}}',
            '\sectnum ',
            '{\super \1\super0}',
            '{\sub \1\sub0}',
//            '\page ',
//            '\sect '
        );

        $text = preg_replace($search, $replace, $text);
        $text = html_entity_decode($text, ENT_COMPAT, $charset);

        return $text;
    }
866405
static function strtolower( $text )
    {
        //We need to detect our internal charset
        if ( self::$charset === null )
        {
            self::$charset = eZTextCodec::internalCharset();
        }

        //First try to use mbstring
        if ( extension_loaded( 'mbstring' ) )
        {
            return mb_strtolower( $text, self::$charset );
        }
        else
        {
            // Fall back if mbstring is not available
            $char = eZCharTransform::instance();
            return $char->transformByGroup( $text, 'lowercase' );
        }
    }
619350
public function setCharacterSet($charset)
    {
        $this->charset = $charset;
        $this->charReader = null;
        $this->mapType = 0;
    }
407364
public static function encode($encodingLabel, $text)
    {
        $encodingLabel = self::normalizeEncoding($encodingLabel);
        if ($encodingLabel === 'UTF-8') {
            return Encoding::toUTF8($text);
        }
        if ($encodingLabel === 'ISO-8859-1') {
            return Encoding::toLatin1($text);
        }
    }
135741
public static function upper( $string, $encoding = null )
	{
		if ( is_null( $encoding ) )
		{
			$encoding = ClanCats::$config->charset;
		}
		return mb_strtoupper( $string, $encoding );
	}
1270569
static function DecodeFromHTML($string, $charset = null)
	{
		// this only gets named characters
		// return html_entity_decode($string);

		// this is a complex method that appears to be the reverse of UTF8ToHTML
		// taken from http://www.php.net/manual/en/function.html-entity-decode.php#68491
//		$string = self::ReplaceNonNumericEntities($string);
//		$string = preg_replace_callback('~&(#(x?))?([^;]+);~', 'self::html_entity_replace', $string);
//        return $string;

		// this way at least somebody could specify a character set.  UTF-8 will work most of the time
		if ($charset == null) $charset = VerySimpleStringUtil::$DEFAULT_CHARACTER_SET;
		return mb_convert_encoding($string, $charset, 'HTML-ENTITIES');
	}
1144947
function generateCharsetMappingTable( $unicodeTable, $charset )
    {
        $codec = eZTextCodec::instance( 'unicode', $charset );
        if ( !$codec )
        {
            eZDebug::writeError( "Failed to create textcodec for charset '$charset'" );
            return false;
        }

        $charsetTable = array();
        foreach ( $unicodeTable as $match => $replacement )
        {
            $matchLocal = $codec->convertString( array( $match ) );
            if ( is_array( $replacement ) )
            {
                $replacementLocal = $codec->convertString( $replacement );
            }
            else
            {
                $replacementLocal = $codec->convertString( array( $replacement ) );
            }
            $charsetTable[$matchLocal] = $replacementLocal;
        }

        // Make sure longer string entries are placed before the shorter ones
        // This is very important when working with utf8 which have
        // variable length for characters
        krsort( $charsetTable );
        return $charsetTable;
    }
1225516
public function escapeCSS(?string $string, string $charset): string
	{
		if($string === '' || ctype_digit($string))
		{
			return $string;
		}

		if($charset !== 'UTF-8')
		{
			$string = mb_convert_encoding($string, 'UTF-8', $charset);
		}

		$string = preg_replace_callback('/[^a-z0-9]/iSu', [$this, 'cssEscaper'], $string);

		if($charset !== 'UTF-8')
		{
			$string = mb_convert_encoding($string, $charset, 'UTF-8');
		}

		return $string;
	}
913371
public function setOutputCharset($charset)
    {
        $flag = true;
        
        $charset  = strtolower($charset);
        $charsets = array('utf-8', 'windows-1256', 'cp1256', 'iso-8859-6');
        
        if (in_array($charset, $charsets)) {
            if ($charset == 'windows-1256') {
                $charset = 'cp1256';
            }
            $this->_outputCharset = $charset;
        } else {
            $flag = false;
        }
        
        return $flag;
    }
996319
protected function _encode($text)
    {
        $restore = mb_internal_encoding();
        mb_internal_encoding($this->_appCharset);
        if (empty($this->headerCharset)) {
            $this->headerCharset = $this->charset;
        }
        $return = mb_encode_mimeheader($text, $this->headerCharset, 'B');
        mb_internal_encoding($restore);

        return $return;
    }
676340
public function convertToUtf8($str, $charset = 'ISO-8859-1')
    {
        if ($charset == 'default') {
            $charset = 'utf-8';
        }

        $str = iconv($charset, 'UTF-8//IGNORE', $str);

        return $str;
    }