Skip to content

Commit

Permalink
Merge pull request #402 from StudioMaX/utf8-deprecated
Browse files Browse the repository at this point in the history
Remove deprecated utf8_encode/utf8_decode
  • Loading branch information
JamesHeinrich committed Oct 27, 2022
2 parents 0201903 + 4f9133e commit f5c964f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
61 changes: 29 additions & 32 deletions demos/demo.mp3header.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions getid3/getid3.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f5c964f

Please sign in to comment.