From 80e3c46f3a5d28625a610c93a16ceb8239727da4 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Sat, 16 Mar 2013 00:18:38 +0000 Subject: [PATCH] iconv() is more efficient than mb_convert_encoding() --- Classes/PHPExcel/Shared/String.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Classes/PHPExcel/Shared/String.php b/Classes/PHPExcel/Shared/String.php index 3e495e8..31e2ef3 100644 --- a/Classes/PHPExcel/Shared/String.php +++ b/Classes/PHPExcel/Shared/String.php @@ -482,7 +482,7 @@ class PHPExcel_Shared_String } /** - * Convert string from one encoding to another. First try iconv, then mbstring, or no convertion + * Convert string from one encoding to another. First try mbstring, then iconv, finally strlen * * @param string $value * @param string $to Encoding to convert to, e.g. 'UTF-8' @@ -491,14 +491,14 @@ class PHPExcel_Shared_String */ public static function ConvertEncoding($value, $to, $from) { - if (self::getIsIconvEnabled()) { - return iconv($from, $to, $value); - } - if (self::getIsMbstringEnabled()) { return mb_convert_encoding($value, $to, $from); } + if (self::getIsIconvEnabled()) { + return iconv($from, $to, $value); + } + if($from == 'UTF-16LE'){ return self::utf16_decode($value, false); }else if($from == 'UTF-16BE'){ @@ -548,20 +548,20 @@ class PHPExcel_Shared_String */ public static function CountCharacters($value, $enc = 'UTF-8') { - if (self::getIsIconvEnabled()) { - return iconv_strlen($value, $enc); - } - if (self::getIsMbstringEnabled()) { return mb_strlen($value, $enc); } + if (self::getIsIconvEnabled()) { + return iconv_strlen($value, $enc); + } + // else strlen return strlen($value); } /** - * Get a substring of a UTF-8 encoded string + * Get a substring of a UTF-8 encoded string. First try mbstring, then iconv, finally strlen * * @param string $pValue UTF-8 encoded string * @param int $start Start offset @@ -570,14 +570,14 @@ class PHPExcel_Shared_String */ public static function Substring($pValue = '', $pStart = 0, $pLength = 0) { - if (self::getIsIconvEnabled()) { - return iconv_substr($pValue, $pStart, $pLength, 'UTF-8'); - } - if (self::getIsMbstringEnabled()) { return mb_substr($pValue, $pStart, $pLength, 'UTF-8'); } + if (self::getIsIconvEnabled()) { + return iconv_substr($pValue, $pStart, $pLength, 'UTF-8'); + } + // else substr return substr($pValue, $pStart, $pLength); }