97 for ($i = 0; $i <= 31; ++$i) {
98 if ($i != 9 && $i != 10 && $i != 13) {
99 $find =
'_x' . sprintf(
'%04s' , strtoupper(dechex($i))) .
'_';
101 self::$_controlCharacters[$find] = $replace;
111 self::$_SYLKCharacters =
array(
144 "\x1B'?" => chr(127),
278 if (isset(self::$_isMbstringEnabled)) {
279 return self::$_isMbstringEnabled;
282 self::$_isMbstringEnabled = function_exists(
'mb_convert_encoding') ?
285 return self::$_isMbstringEnabled;
295 if (isset(self::$_isIconvEnabled)) {
296 return self::$_isIconvEnabled;
300 if (!function_exists(
'iconv')) {
301 self::$_isIconvEnabled =
false;
306 if (!@iconv(
'UTF-8',
'UTF-16LE',
'x')) {
307 self::$_isIconvEnabled =
false;
313 if (!@iconv_substr(
'A', 0, 1,
'UTF-8')) {
314 self::$_isIconvEnabled =
false;
319 if (
defined(
'PHP_OS') && @stristr(PHP_OS,
'AIX')
320 &&
defined(
'ICONV_IMPL') && (@strcasecmp(ICONV_IMPL,
'unknown') == 0)
321 &&
defined(
'ICONV_VERSION') && (@strcasecmp(ICONV_VERSION,
'unknown') == 0) )
323 self::$_isIconvEnabled =
false;
328 self::$_isIconvEnabled =
true;
333 if(empty(self::$_controlCharacters)) {
334 self::_buildControlCharacters();
336 if(empty(self::$_SYLKCharacters)) {
337 self::_buildSYLKCharacters();
356 return str_replace( array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value );
374 return str_replace( array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value );
385 if (self::getIsIconvEnabled()) {
386 $value = @iconv(
'UTF-8',
'UTF-8', $value);
390 if (self::getIsMbstringEnabled()) {
391 $value = mb_convert_encoding($value,
'UTF-8',
'UTF-8');
405 public static function IsUTF8($value =
'') {
406 return $value ===
'' || preg_match(
'/^./su', $value) === 1;
417 if (is_float($value)) {
418 return str_replace(
',',
'.', $value);
420 return (
string) $value;
437 $ln = self::CountCharacters($value,
'UTF-8');
439 if(empty($arrcRuns)){
440 $opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
442 $data = pack(
'CC', $ln, $opt);
444 $data .= self::ConvertEncoding($value,
'UTF-16LE',
'UTF-8');
447 $data = pack(
'vC', $ln, 0x09);
448 $data .= pack(
'v', count($arrcRuns));
450 $data .= self::ConvertEncoding($value,
'UTF-16LE',
'UTF-8');
451 foreach ($arrcRuns as $cRun){
452 $data .= pack(
'v', $cRun[
'strlen']);
453 $data .= pack(
'v', $cRun[
'fontidx']);
472 $ln = self::CountCharacters($value,
'UTF-8');
475 $opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
479 $chars = self::ConvertEncoding($value,
'UTF-16LE',
'UTF-8');
481 $data = pack(
'vC', $ln, $opt) . $chars;
495 if (self::getIsIconvEnabled()) {
496 return iconv($from, $to, $value);
499 if (self::getIsMbstringEnabled()) {
500 return mb_convert_encoding($value, $to, $from);
503 if($from ==
'UTF-16LE'){
504 return self::utf16_decode($value,
false);
505 }
else if($from ==
'UTF-16BE'){
506 return self::utf16_decode($value);
528 if( strlen($str) < 2 )
return $str;
531 if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
532 elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be =
false; }
535 for($i=0;$i<$len;$i+=2) {
536 if( $bom_be ) { $val = ord($str{$i}) << 4; $val += ord($str{$i+1}); }
537 else { $val = ord($str{$i+1}) << 4; $val += ord($str{$i}); }
538 $newstr .= ($val == 0x228) ?
"\n" : chr($val);
552 if (self::getIsMbstringEnabled()) {
553 return mb_strlen($value, $enc);
556 if (self::getIsIconvEnabled()) {
557 return iconv_strlen($value, $enc);
561 return strlen($value);
572 public static function Substring($pValue =
'', $pStart = 0, $pLength = 0)
574 if (self::getIsMbstringEnabled()) {
575 return mb_substr($pValue, $pStart, $pLength,
'UTF-8');
578 if (self::getIsIconvEnabled()) {
579 return iconv_substr($pValue, $pStart, $pLength,
'UTF-8');
583 return substr($pValue, $pStart, $pLength);
594 if (function_exists(
'mb_convert_case')) {
595 return mb_convert_case($pValue, MB_CASE_UPPER,
"UTF-8");
597 return strtoupper($pValue);
608 if (function_exists(
'mb_convert_case')) {
609 return mb_convert_case($pValue, MB_CASE_LOWER,
"UTF-8");
611 return strtolower($pValue);
623 if (function_exists(
'mb_convert_case')) {
624 return mb_convert_case($pValue, MB_CASE_TITLE,
"UTF-8");
626 return ucwords($pValue);
631 return mb_strtolower($char,
"UTF-8") != $char;
636 # Split at all position not after the start: ^ 637 # and not before the end: $ 638 return preg_split(
'/(?<!^)(?!$)/u', $string );
650 if (self::getIsMbstringEnabled()) {
651 $characters = self::mb_str_split($pValue);
652 foreach($characters as &$character) {
653 if(self::mb_is_upper($character)) {
654 $character = mb_strtolower($character,
'UTF-8');
656 $character = mb_strtoupper($character,
'UTF-8');
659 return implode(
'', $characters);
661 return strtolower($pValue) ^ strtoupper($pValue) ^ $pValue;
672 if (preg_match(
'/^'.self::STRING_REGEXP_FRACTION.
'$/i', $operand, $match)) {
673 $sign = ($match[1] ==
'-') ?
'-' :
'+';
674 $fractionFormula =
'='.$sign.$match[2].$sign.$match[3];
689 if (!isset(self::$_decimalSeparator)) {
690 $localeconv = localeconv();
691 self::$_decimalSeparator = ($localeconv[
'decimal_point'] !=
'')
692 ? $localeconv[
'decimal_point'] : $localeconv[
'mon_decimal_point'];
694 if (self::$_decimalSeparator ==
'') {
696 self::$_decimalSeparator =
'.';
699 return self::$_decimalSeparator;
710 self::$_decimalSeparator = $pValue;
721 if (!isset(self::$_thousandsSeparator)) {
722 $localeconv = localeconv();
723 self::$_thousandsSeparator = ($localeconv[
'thousands_sep'] !=
'')
724 ? $localeconv[
'thousands_sep'] : $localeconv[
'mon_thousands_sep'];
726 if (self::$_thousandsSeparator ==
'') {
728 self::$_thousandsSeparator =
',';
731 return self::$_thousandsSeparator;
742 self::$_thousandsSeparator = $pValue;
753 if (!isset(self::$_currencyCode)) {
754 $localeconv = localeconv();
755 self::$_currencyCode = ($localeconv[
'currency_symbol'] !=
'')
756 ? $localeconv[
'currency_symbol'] : $localeconv[
'int_curr_symbol'];
758 if (self::$_currencyCode ==
'') {
760 self::$_currencyCode =
'$';
763 return self::$_currencyCode;
774 self::$_currencyCode = $pValue;
786 if (strpos($pValue,
'') ===
false) {
790 foreach (self::$_SYLKCharacters as $k => $v) {
791 $pValue = str_replace($k, $v, $pValue);
806 if (is_numeric($value))
808 $v = floatval($value);
809 return (is_numeric(substr($value, 0, strlen($v)))) ? $v : $value;
static getCurrencyCode()
Get the currency code.
static utf16_decode($str, $bom_be=TRUE)
Decode UTF-16 encoded strings.
const STRING_REGEXP_FRACTION
Constants.
static setCurrencyCode($pValue='$')
Set the currency code.
static setDecimalSeparator($pValue='.')
Set the decimal separator.
static UTF8toBIFF8UnicodeLong($value)
Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length) Writes the string using...
static ConvertEncoding($value, $to, $from)
Convert string from one encoding to another.
static FormatNumber($value)
Formats a numeric value as a string for output in various output writers forcing point as decimal sep...
static StrToUpper($pValue='')
Convert a UTF-8 encoded string to upper case.
static StrToTitle($pValue='')
Convert a UTF-8 encoded string to title/proper case (uppercase every first character in each word...
static getThousandsSeparator()
Get the thousands separator.
static buildCharacterSets()
static convertToNumberIfFraction(&$operand)
Identify whether a string contains a fractional numeric value, and convert it to a numeric if it is...
static StrCaseReverse($pValue='')
Reverse the case of a string, so that all uppercase characters become lowercase and all lowercase cha...
static testStringAsNumeric($value)
Retrieve any leading numeric part of a string, or return the full string if no leading numeric (handl...
static getIsMbstringEnabled()
Get whether mbstring extension is available.
static setThousandsSeparator($pValue=',')
Set the thousands separator.
static _buildControlCharacters()
Build control characters array.
static IsUTF8($value='')
Check if a string contains UTF8 data.
static UTF8toBIFF8UnicodeShort($value, $arrcRuns=array())
Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length) Writes the string using ...
static $_thousandsSeparator
static $_decimalSeparator
static $_controlCharacters
static getIsIconvEnabled()
Get whether iconv extension is available.
static mb_str_split($string)
Create styles array
The data for the language used.
static Substring($pValue='', $pStart=0, $pLength=0)
Get a substring of a UTF-8 encoded string.
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
static mb_is_upper($char)
static getDecimalSeparator()
Get the decimal separator.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
static SanitizeUTF8($value)
Try to sanitize UTF8, stripping invalid byte sequences.
static $_SYLKCharacters
SYLK Characters array.
static SYLKtoUTF8($pValue='')
Convert SYLK encoded string to UTF-8.
static StrToLower($pValue='')
Convert a UTF-8 encoded string to lower case.
static CountCharacters($value, $enc='UTF-8')
Get character count.
static $_isMbstringEnabled
static ControlCharacterPHP2OOXML($value='')
Convert from PHP control character to OpenXML escaped control character.
static _buildSYLKCharacters()
Build SYLK characters array.
static ControlCharacterOOXML2PHP($value='')
Convert from OpenXML escaped control character to PHP control character.