Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated utf8_encode/utf8_decode #402

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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