Skip to content

Commit

Permalink
Fixed utf8_encode and utf8_decode functions deprecated in PHP 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
raortegar committed Feb 3, 2023
1 parent 7257fd2 commit 789909d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/Horde/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ protected static function _convertCharset($input, $from, $to)
!Horde_Util::extensionExists('iconv') ||
!Horde_Util::extensionExists('mbstring'))) {
if (($to == 'utf-8') &&
function_exists('utf8_encode') &&
in_array($from, array('iso-8859-1', 'us-ascii', 'utf-8'))) {
return utf8_encode($input);
return @utf8_encode($input);
}

if (($from == 'utf-8') &&
function_exists('utf8_decode') &&
in_array($to, array('iso-8859-1', 'us-ascii', 'utf-8'))) {
return utf8_decode($input);
return @utf8_decode($input);
}
}

Expand Down Expand Up @@ -381,7 +383,12 @@ public static function length($string, $charset = 'UTF-8')
$charset = self::lower($charset);

if ($charset == 'utf-8' || $charset == 'utf8') {
return strlen(utf8_decode($string));
if (Horde_Util::extensionExists('mbstring')) {
return strlen(mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8'));

} else if (function_exists('utf8_decode')) {
return strlen(@utf8_decode($string));
}
}

if (Horde_Util::extensionExists('mbstring')) {
Expand Down

0 comments on commit 789909d

Please sign in to comment.