diff --git a/demos/demo.mp3header.php b/demos/demo.mp3header.php index 222fe40e..57c241c8 100644 --- a/demos/demo.mp3header.php +++ b/demos/demo.mp3header.php @@ -705,7 +705,7 @@ function RoughTranslateUnicodeToASCII($rawdata, $frame_textencoding) { break; case 3: // UTF-8 encoded Unicode. Terminated with $00. - $asciidata = utf8_decode($rawdata); + $asciidata = utf8_to_iso8859_1($rawdata); break; case 255: // Unicode, Big-Endian. Terminated with $00 00. @@ -929,43 +929,40 @@ function image_type_to_mime_type($imagetypeid) { } } -if (!function_exists('utf8_decode')) { - // PHP has this function built-in if it's configured with the --with-xml option - // This version of the function is only provided in case XML isn't installed - function utf8_decode($utf8text) { - // http://www.php.net/manual/en/function.utf8-encode.php - // bytes bits representation - // 1 7 0bbbbbbb - // 2 11 110bbbbb 10bbbbbb - // 3 16 1110bbbb 10bbbbbb 10bbbbbb - // 4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - - $utf8length = strlen($utf8text); - $decodedtext = ''; - for ($i = 0; $i < $utf8length; $i++) { - if ((ord($utf8text[$i]) & 0x80) == 0) { - $decodedtext .= $utf8text[$i]; - } elseif ((ord($utf8text[$i]) & 0xF0) == 0xF0) { - $decodedtext .= '?'; - $i += 3; - } elseif ((ord($utf8text[$i]) & 0xE0) == 0xE0) { +function utf8_to_iso8859_1($utf8text) { + // http://www.php.net/manual/en/function.utf8-encode.php + // bytes bits representation + // 1 7 0bbbbbbb + // 2 11 110bbbbb 10bbbbbb + // 3 16 1110bbbb 10bbbbbb 10bbbbbb + // 4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb + + $utf8length = strlen($utf8text); + $decodedtext = ''; + for ($i = 0; $i < $utf8length; $i++) { + if ((ord($utf8text[$i]) & 0x80) == 0) { + $decodedtext .= $utf8text[$i]; + } elseif ((ord($utf8text[$i]) & 0xF0) == 0xF0) { + $decodedtext .= '?'; + $i += 3; + } elseif ((ord($utf8text[$i]) & 0xE0) == 0xE0) { + $decodedtext .= '?'; + $i += 2; + } elseif ((ord($utf8text[$i]) & 0xC0) == 0xC0) { + // 2 11 110bbbbb 10bbbbbb + $decodedchar = Bin2Dec(substr(Dec2Bin(ord($utf8text[$i])), 3, 5).substr(Dec2Bin(ord($utf8text[($i + 1)])), 2, 6)); + if ($decodedchar <= 255) { + $decodedtext .= chr($decodedchar); + } else { $decodedtext .= '?'; - $i += 2; - } elseif ((ord($utf8text[$i]) & 0xC0) == 0xC0) { - // 2 11 110bbbbb 10bbbbbb - $decodedchar = Bin2Dec(substr(Dec2Bin(ord($utf8text[$i])), 3, 5).substr(Dec2Bin(ord($utf8text[($i + 1)])), 2, 6)); - if ($decodedchar <= 255) { - $decodedtext .= chr($decodedchar); - } else { - $decodedtext .= '?'; - } - $i += 1; } + $i += 1; } - return $decodedtext; } + return $decodedtext; } + if (!function_exists('DateMac2Unix')) { function DateMac2Unix($macdate) { // Macintosh timestamp: seconds since 00:00h January 1, 1904 diff --git a/getid3/getid3.lib.php b/getid3/getid3.lib.php index c154fbda..d84bb4b6 100644 --- a/getid3/getid3.lib.php +++ b/getid3/getid3.lib.php @@ -871,10 +871,6 @@ public static function iconv_fallback_int_utf8($charval) { * @return string */ public static function iconv_fallback_iso88591_utf8($string, $bom=false) { - if (function_exists('utf8_encode')) { - return utf8_encode($string); - } - // utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support) $newcharstring = ''; if ($bom) { $newcharstring .= "\xEF\xBB\xBF"; @@ -943,10 +939,6 @@ public static function iconv_fallback_iso88591_utf16($string) { * @return string */ public static function iconv_fallback_utf8_iso88591($string) { - if (function_exists('utf8_decode')) { - return utf8_decode($string); - } - // utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support) $newcharstring = ''; $offset = 0; $stringlength = strlen($string);