选择语言 :

 Core_UTF8::clean

Recursively cleans arrays, objects, and strings. Removes ASCII control codes and converts to the requested charset while silently discarding incompatible characters.

UTF8::clean($_GET); // Clean GET data

This method requires Iconv
mixed Core_UTF8::clean( mixed $var [, string $charset = string(5) "UTF-8" ] )
uses
UTF8::strip_ascii_ctrl
UTF8::is_ascii

参数列表

参数 类型 描述 默认值
$var mixed Variable to clean
$charset string Character set, defaults to UTF-8 string(5) "UTF-8"
返回值
  • mixed
File: ./core/classes/utf8.class.php
public static function clean($var, $charset = 'UTF-8')
{
    if (is_array($var) || is_object($var))
    {
        foreach ($var as $key => $val)
        {
            // Recursion!
            $var[self::clean($key)] = self::clean($val);
        }
    }
    elseif ( is_string($var) and $var !== '' )
    {
        // Remove control characters
        $var = self::strip_ascii_ctrl($var);

        if ( !self::is_ascii($var) )
        {
            // Disable notices
            $ER = error_reporting(~ E_NOTICE);

            // iconv is expensive, so it is only used when needed
            $var = iconv($charset, $charset . '//IGNORE', $var);

            // Turn notices back on
            error_reporting($ER);
        }
    }

    return $var;
}