From 2dbb9393671d33639a44b448a34ada5c1d7419f2 Mon Sep 17 00:00:00 2001 From: KONE SOREL Date: Mon, 29 Dec 2025 09:06:33 +0000 Subject: [PATCH] PHPExcel --- PHPExcel/PHPExcel/Shared/String.php | 31 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/PHPExcel/PHPExcel/Shared/String.php b/PHPExcel/PHPExcel/Shared/String.php index 49d217a..9105a2d 100755 --- a/PHPExcel/PHPExcel/Shared/String.php +++ b/PHPExcel/PHPExcel/Shared/String.php @@ -525,21 +525,34 @@ class PHPExcel_Shared_String * @author vadik56 */ public static function utf16_decode($str, $bom_be = TRUE) { - if( strlen($str) < 2 ) return $str; - $c0 = ord($str{0}); - $c1 = ord($str{1}); - if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); } - elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; } + if (strlen($str) < 2) return $str; + + $c0 = ord($str[0]); + $c1 = ord($str[1]); + + if ($c0 == 0xfe && $c1 == 0xff) { + $str = substr($str, 2); + } elseif ($c0 == 0xff && $c1 == 0xfe) { + $str = substr($str, 2); + $bom_be = false; + } + $len = strlen($str); $newstr = ''; - for($i=0;$i<$len;$i+=2) { - if( $bom_be ) { $val = ord($str{$i}) << 4; $val += ord($str{$i+1}); } - else { $val = ord($str{$i+1}) << 4; $val += ord($str{$i}); } + + for ($i = 0; $i < $len; $i += 2) { + if ($bom_be) { + $val = ord($str[$i]) << 4; + $val += ord($str[$i + 1]); + } else { + $val = ord($str[$i + 1]) << 4; + $val += ord($str[$i]); + } $newstr .= ($val == 0x228) ? "\n" : chr($val); } + return $newstr; } - /** * Get character count. First try mbstring, then iconv, finally strlen *