Skip to content

Commit

Permalink
Merge pull request #11 from raortegar/fix_utf8_encode_deprecation
Browse files Browse the repository at this point in the history
Fixed utf8_encode and utf8_decode functions deprecated in PHP 8.2
  • Loading branch information
mrubinsk committed May 19, 2023
2 parents 55dfade + 789909d commit 2c91b6e
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 2c91b6e

Please sign in to comment.