@@ 3004-3051 (lines=48) @@ | ||
3001 | * <strong>2</strong> for UTF-16BE. |
|
3002 | * </p> |
|
3003 | */ |
|
3004 | public static function is_utf16($str) |
|
3005 | { |
|
3006 | $str = self::remove_bom($str); |
|
3007 | ||
3008 | if (self::is_binary($str) === true) { |
|
3009 | ||
3010 | $maybeUTF16LE = 0; |
|
3011 | $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16LE'); |
|
3012 | if ($test) { |
|
3013 | $test2 = \mb_convert_encoding($test, 'UTF-16LE', 'UTF-8'); |
|
3014 | $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16LE'); |
|
3015 | if ($test3 === $test) { |
|
3016 | $strChars = self::count_chars($str, true); |
|
3017 | foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) { |
|
3018 | if (in_array($test3char, $strChars, true) === true) { |
|
3019 | $maybeUTF16LE++; |
|
3020 | } |
|
3021 | } |
|
3022 | } |
|
3023 | } |
|
3024 | ||
3025 | $maybeUTF16BE = 0; |
|
3026 | $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16BE'); |
|
3027 | if ($test) { |
|
3028 | $test2 = \mb_convert_encoding($test, 'UTF-16BE', 'UTF-8'); |
|
3029 | $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16BE'); |
|
3030 | if ($test3 === $test) { |
|
3031 | $strChars = self::count_chars($str, true); |
|
3032 | foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) { |
|
3033 | if (in_array($test3char, $strChars, true) === true) { |
|
3034 | $maybeUTF16BE++; |
|
3035 | } |
|
3036 | } |
|
3037 | } |
|
3038 | } |
|
3039 | ||
3040 | if ($maybeUTF16BE !== $maybeUTF16LE) { |
|
3041 | if ($maybeUTF16LE > $maybeUTF16BE) { |
|
3042 | return 1; |
|
3043 | } |
|
3044 | ||
3045 | return 2; |
|
3046 | } |
|
3047 | ||
3048 | } |
|
3049 | ||
3050 | return false; |
|
3051 | } |
|
3052 | ||
3053 | /** |
|
3054 | * Check if the string is UTF-32. |
|
@@ 3064-3111 (lines=48) @@ | ||
3061 | * <strong>2</strong> for UTF-32BE. |
|
3062 | * </p> |
|
3063 | */ |
|
3064 | public static function is_utf32($str) |
|
3065 | { |
|
3066 | $str = self::remove_bom($str); |
|
3067 | ||
3068 | if (self::is_binary($str) === true) { |
|
3069 | ||
3070 | $maybeUTF32LE = 0; |
|
3071 | $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32LE'); |
|
3072 | if ($test) { |
|
3073 | $test2 = \mb_convert_encoding($test, 'UTF-32LE', 'UTF-8'); |
|
3074 | $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32LE'); |
|
3075 | if ($test3 === $test) { |
|
3076 | $strChars = self::count_chars($str, true); |
|
3077 | foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) { |
|
3078 | if (in_array($test3char, $strChars, true) === true) { |
|
3079 | $maybeUTF32LE++; |
|
3080 | } |
|
3081 | } |
|
3082 | } |
|
3083 | } |
|
3084 | ||
3085 | $maybeUTF32BE = 0; |
|
3086 | $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32BE'); |
|
3087 | if ($test) { |
|
3088 | $test2 = \mb_convert_encoding($test, 'UTF-32BE', 'UTF-8'); |
|
3089 | $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32BE'); |
|
3090 | if ($test3 === $test) { |
|
3091 | $strChars = self::count_chars($str, true); |
|
3092 | foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) { |
|
3093 | if (in_array($test3char, $strChars, true) === true) { |
|
3094 | $maybeUTF32BE++; |
|
3095 | } |
|
3096 | } |
|
3097 | } |
|
3098 | } |
|
3099 | ||
3100 | if ($maybeUTF32BE !== $maybeUTF32LE) { |
|
3101 | if ($maybeUTF32LE > $maybeUTF32BE) { |
|
3102 | return 1; |
|
3103 | } |
|
3104 | ||
3105 | return 2; |
|
3106 | } |
|
3107 | ||
3108 | } |
|
3109 | ||
3110 | return false; |
|
3111 | } |
|
3112 | ||
3113 | /** |
|
3114 | * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters. |