Attempts to convert a string to UTF-8 and clean any non-valid UTF-8 characters.

@param string $string
@return string
198158
public static function convertToUtf8(string $string): string
    {
        // If it's already a UTF8 string, just clean and return it
        if (static::isUtf8($string)) {
            return HtmlPurifier::cleanUtf8($string);
        }

        // Otherwise set HTMLPurifier to the actual string encoding
        $config = \HTMLPurifier_Config::createDefault();
        $config->set('Core.Encoding', static::encoding($string));

        // Clean it
        $string = HtmlPurifier::cleanUtf8($string);

        // Convert it to UTF8 if possible
        if (function_exists('iconv') && \HTMLPurifier_Encoder::testIconvTruncateBug() === \HTMLPurifier_Encoder::ICONV_OK) {
            $string = HtmlPurifier::convertToUtf8($string, $config);
        } else {
            $encoding = static::encoding($string);
            $string = mb_convert_encoding($string, 'utf-8', $encoding);
        }

        return $string;
    }
862368
public function asUTF8($string)
    {
        if (CKFinder_Connector_Utils_Misc::isValidUTF8($string)) {
            return $string;
        }

        $ret = "";
        for ($i = 0; $i < strlen($string); $i++) {
            $ret .= CKFinder_Connector_Utils_Misc::isValidUTF8($string[$i]) ? $string[$i] : "?";
        }

        return $ret;
    }
1038627
public static function strlen($string, $charset = self::UTF8)
	{
		switch (strtolower($charset))
		{
			case self::GBK:
				$count = self::strlenForGbk($string);
				break;
			case self::UTF8:
				$count = self::strlenForUtf8($string);
				break;
			default:
				$count = strlen($string);
		}
		return $count;
	}
1047138
public function toUTF8($string)
    {
        /**
         * (8x except 85, 8C) + (9x except 9C) + (BC, BD, BE)
         */
        static $macchars = "\x81\x82\x83\x84\x86\x87\x88\x89\x8A\x8B\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9D\x9E\x9F\xBC\xBD\xBE";

        if (mb_convert_encoding(mb_convert_encoding($string, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32') == $string) {
            $mac = mb_convert_encoding($string, 'windows-1252', 'UTF-8');
            for ($i = strlen($mac); $i;) {
                if (strpos($macchars, $mac[ -- $i]) !== false) {
                    return(iconv('MACINTOSH', 'UTF-8', $mac));
                }
            }

            return($string);
        } else {
            for ($i = strlen($string); $i;) {
                if (strpos($macchars, $string[ -- $i]) !== false) {
                    return(iconv('MACINTOSH', 'UTF-8', $string));
                }
            }

            return(iconv('windows-1252', 'UTF-8', $string));
        }
    }
741815
function clean_string($str)
	{
		if ($this->_is_ascii($str) === FALSE)
		{
			$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
		}

		return $str;
	}
1303744
public function escape($string)
    {
        $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8');
        $string = str_replace('{{', '', $string);
        $string = str_replace('}}', '', $string);

        return htmlentities($string, ENT_QUOTES, 'UTF-8');
    }
963285
public static function hardDecode($string) {
		$data = htmlspecialchars_decode($string);
		$data = html_entity_decode($data);
		$data = strip_tags($data);
		$data = chop(Utility::convert_smart_quotes($data));
		$data = str_replace(array("\r", "\n", "	"), "", $data);

		return ($data);
	}
820933
public static function strlen( $string )
    {
        if ( false === ( $_encoding = static::mbSupported( $string ) ) )
        {
            return strlen( $string );
        }

        return mb_strwidth( $string, $_encoding );
    }
331926
public static function cleanse(string $string): string
    {
        return trim(
            htmlspecialchars_decode(
                strip_tags(
                    str_replace(['<br>', '<br/>', '<br />'], '\n', $string)
                ),
                ENT_QUOTES
            )
        );
    }
618337
public static String decodeString(final String string) {
		String decodedString = null;

		try {
			byte[] decodedBytes = decode(string);
			decodedString = new String(decodedBytes, "UTF-8");
		} catch (UnsupportedEncodingException uue) {
			// Should never happen, java has to support "UTF-8".
		}

		return decodedString;
	}
842607
protected function strlen($string)
    {
        // don't count color codes
        $string = preg_replace("/\33\\[\\d+(;\\d+)?m/", '', $string);

        if (function_exists('mb_strlen')) {
            return mb_strlen($string, 'utf-8');
        }

        return strlen($string);
    }
1017678
protected function convertCharset($string, $charsets)
    {
        if (function_exists('iconv')
            && !empty($charsets)
        ) {
            $charset = $charsets[0];
            if (count($charsets) > 1
                && function_exists('mb_detect_encoding')
            ) {
                $charset = mb_detect_encoding($string, $charsets);
                if ($charset === false) {
                    $charset = $charsets[0];
                }
            }

            $newKey = @iconv($charset, 'UTF-8//IGNORE', $string);
            if (!empty($newKey)) {
                $string = $newKey;
            }
        }

        return $string;
    }
16723
public static function iconv_fallback_utf16_iso88591($string) {
		$bom = substr($string, 0, 2);
		if ($bom == "\xFE\xFF") {
			return self::iconv_fallback_utf16be_iso88591(substr($string, 2));
		} elseif ($bom == "\xFF\xFE") {
			return self::iconv_fallback_utf16le_iso88591(substr($string, 2));
		}
		return $string;
	}
58293
public static function strtoupper($string)
    {
        if(!defined('UTF8_NOMBSTRING') && function_exists('mb_strtolower'))
            return mb_strtoupper($string,'utf-8');

        //global $utf8_lower_to_upper;
        $uni = self::utf8_to_unicode($string);
        $cnt = count($uni);
        for ($i=0; $i < $cnt; $i++){
            if(self::$utf8_lower_to_upper[$uni[$i]]){
                $uni[$i] = self::$utf8_lower_to_upper[$uni[$i]];
            }
        }
        return self::unicode_to_utf8($uni);
    }
947832
public static function strToUpper($string)
    {
        $string = str_replace(self::$lowerTR, self::$upperTR, $string);

        return mb_strtoupper($string, 'UTF-8');
    }
1056132
public static function cleanUnicode($string)
    {
        $character = array_keys(self::$unicodeCharacterMap); // but: for efficiency you should
        $replace = array_values(self::$unicodeCharacterMap); // pre-calculate these two arrays
        return str_replace($character, $replace, html_entity_decode($string, ENT_QUOTES, "UTF-8"));
    }
21362
public static function toUtf8($string)
    {
        $string = explode('@', $string);

        // Not addressing UTF-8 user names
        $new = $string[0];

        if (!empty($string[1])) {
            $domainExploded = explode('.', $string[1]);
            $newdomain      = '';

            foreach ($domainExploded as $domainex) {
                $domainex  = static::decode($domainex);
                $newdomain .= $domainex . '.';
            }

            $newdomain = substr($newdomain, 0, -1);
            $new       = $new . '@' . $newdomain;
        }

        return $new;
    }