public static function seemsUtf8($string)
    {
        for ($i = 0; $i < strlen($string); $i++) {
            if (ord($string[$i]) < 0x80) continue; # 0bbbbbbb
            elseif ((ord($string[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
            elseif ((ord($string[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
            elseif ((ord($string[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
            elseif ((ord($string[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
            elseif ((ord($string[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
            else return false; # Does not match any model
            for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
                if ((++$i == strlen($string)) || ((ord($string[$i]) & 0xC0) != 0x80))
                return false;
            }
        }
        return true;
    }
public static function seemsUtf8($string)
    {
        for ($i = 0; $i < strlen($string); $i++) {
            if (ord($string[$i]) < 0x80) continue; # 0bbbbbbb
            elseif ((ord($string[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
            elseif ((ord($string[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
            elseif ((ord($string[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
            elseif ((ord($string[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
            elseif ((ord($string[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
            else return false; # Does not match any model
            for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
                if ((++$i == strlen($string)) || ((ord($string[$i]) & 0xC0) != 0x80))
                return false;
            }
        }
        return true;
    }
public static function seemsUtf8 ( $ string ) { for ( $ i = 0 ; $ i < strlen ( $ string ) ; $ i ++ ) { if ( ord ( $ string [ $ i ] ) < 0x80 ) continue ; # 0bbbbbbb elseif ( ( ord ( $ string [ $ i ] ) & 0xE0 ) == 0xC0 ) $ n = 1 ; # 110bbbbb elseif ( ( ord ( $ string [ $ i ] ) & 0xF0 ) == 0xE0 ) $ n = 2 ; # 1110bbbb elseif ( ( ord ( $ string [ $ i ] ) & 0xF8 ) == 0xF0 ) $ n = 3 ; # 11110bbb elseif ( ( ord ( $ string [ $ i ] ) & 0xFC ) == 0xF8 ) $ n = 4 ; # 111110bb elseif ( ( ord ( $ string [ $ i ] ) & 0xFE ) == 0xFC ) $ n = 5 ; # 1111110b else return false ; # Does not match any model for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { # n bytes matching 10bbbbbb follow ? if ( ( ++ $ i == strlen ( $ string ) ) || ( ( ord ( $ string [ $ i ] ) & 0xC0 ) != 0x80 ) ) return false ; } } return true ; }
Check if a string has utf7 characters in it

By bmorel at ssi dot fr

@param  string $string
@return boolean $bool
Check if a string has utf7 characters in it