mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-25 23:06:03 +03:00
iconv() is more efficient than mb_convert_encoding()
This commit is contained in:
parent
316f86e03c
commit
80e3c46f3a
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user