PHPUnit_Util_XML::isUtf8 PHP Method

isUtf8() protected static method

Checks a string for UTF-8 encoding.
protected static isUtf8 ( string $string ) : boolean
$string string
return boolean
    protected static function isUtf8($string)
    {
        $length = strlen($string);
        for ($i = 0; $i < $length; $i++) {
            if (ord($string[$i]) < 0x80) {
                $n = 0;
            } else {
                if ((ord($string[$i]) & 0xe0) == 0xc0) {
                    $n = 1;
                } else {
                    if ((ord($string[$i]) & 0xf0) == 0xe0) {
                        $n = 2;
                    } else {
                        if ((ord($string[$i]) & 0xf0) == 0xf0) {
                            $n = 3;
                        } else {
                            return FALSE;
                        }
                    }
                }
            }
            for ($j = 0; $j < $n; $j++) {
                if (++$i == $length || (ord($string[$i]) & 0xc0) != 0x80) {
                    return FALSE;
                }
            }
        }
        return TRUE;
    }