68 for (
$i = 0;
$i <= 31; ++
$i) {
69 if (
$i != 9 &&
$i != 10 &&
$i != 13) {
70 $find =
'_x' . sprintf(
'%04s', strtoupper(dechex(
$i))) .
'_';
72 self::$controlCharacters[$find] = $replace;
82 self::$SYLKCharacters = [
115 "\x1B'?" => chr(127),
249 if (isset(self::$isIconvEnabled)) {
250 return self::$isIconvEnabled;
254 self::$isIconvEnabled =
true;
257 if (!function_exists(
'iconv')) {
258 self::$isIconvEnabled =
false;
259 } elseif (!@iconv(
'UTF-8',
'UTF-16LE',
'x')) {
261 self::$isIconvEnabled =
false;
262 } elseif (defined(
'PHP_OS') && @stristr(PHP_OS,
'AIX') && defined(
'ICONV_IMPL') && (@strcasecmp(ICONV_IMPL,
'unknown') == 0) && defined(
'ICONV_VERSION') && (@strcasecmp(ICONV_VERSION,
'unknown') == 0)) {
264 self::$isIconvEnabled =
false;
268 if (self::$isIconvEnabled && !@iconv(
'UTF-8',
'UTF-16LE' . self::$iconvOptions,
'x')) {
269 self::$iconvOptions =
'';
272 return self::$isIconvEnabled;
277 if (empty(self::$controlCharacters)) {
278 self::buildControlCharacters();
281 if (empty(self::$SYLKCharacters)) {
282 self::buildSYLKCharacters();
303 self::buildCharacterSets();
305 return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value);
325 self::buildCharacterSets();
327 return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value);
339 if (self::getIsIconvEnabled()) {
340 $value = @iconv(
'UTF-8',
'UTF-8', $value);
345 $value = mb_convert_encoding($value,
'UTF-8',
'UTF-8');
359 return $value ===
'' || preg_match(
'/^./su', $value) === 1;
372 if (is_float($value)) {
373 return str_replace(
',',
'.', $value);
376 return (
string) $value;
394 $ln = self::countCharacters($value,
'UTF-8');
396 if (empty($arrcRuns)) {
397 $data = pack(
'CC', $ln, 0x0001);
399 $data .= self::convertEncoding($value,
'UTF-16LE',
'UTF-8');
401 $data = pack(
'vC', $ln, 0x09);
402 $data .= pack(
'v', count($arrcRuns));
404 $data .= self::convertEncoding($value,
'UTF-16LE',
'UTF-8');
405 foreach ($arrcRuns as $cRun) {
406 $data .= pack(
'v', $cRun[
'strlen']);
407 $data .= pack(
'v', $cRun[
'fontidx']);
428 $ln = self::countCharacters($value,
'UTF-8');
431 $chars = self::convertEncoding($value,
'UTF-16LE',
'UTF-8');
433 return pack(
'vC', $ln, 0x0001) . $chars;
447 if (self::getIsIconvEnabled()) {
448 $result = iconv(
$from, $to . self::$iconvOptions, $value);
454 return mb_convert_encoding($value, $to,
$from);
467 return mb_strlen($value ??
'', $enc);
479 public static function substring($pValue, $pStart, $pLength = 0)
481 return mb_substr($pValue, $pStart, $pLength,
'UTF-8');
493 return mb_convert_case($pValue, MB_CASE_UPPER,
'UTF-8');
505 return mb_convert_case($pValue, MB_CASE_LOWER,
'UTF-8');
518 return mb_convert_case($pValue, MB_CASE_TITLE,
'UTF-8');
523 return mb_strtolower($char,
'UTF-8') != $char;
530 return preg_split(
'/(?<!^)(?!$)/u', $string);
543 $characters = self::mbStrSplit($pValue);
544 foreach ($characters as &$character) {
545 if (self::mbIsUpper($character)) {
546 $character = mb_strtolower($character,
'UTF-8');
548 $character = mb_strtoupper($character,
'UTF-8');
552 return implode(
'', $characters);
565 if (preg_match(
'/^' . self::STRING_REGEXP_FRACTION .
'$/i', $operand, $match)) {
566 $sign = ($match[1] ==
'-') ?
'-' :
'+';
567 $fractionFormula =
'=' . $sign . $match[2] . $sign . $match[3];
586 if (!isset(self::$decimalSeparator)) {
587 $localeconv = localeconv();
588 self::$decimalSeparator = ($localeconv[
'decimal_point'] !=
'')
589 ? $localeconv[
'decimal_point'] : $localeconv[
'mon_decimal_point'];
591 if (self::$decimalSeparator ==
'') {
593 self::$decimalSeparator =
'.';
597 return self::$decimalSeparator;
608 self::$decimalSeparator = $pValue;
619 if (!isset(self::$thousandsSeparator)) {
620 $localeconv = localeconv();
621 self::$thousandsSeparator = ($localeconv[
'thousands_sep'] !=
'')
622 ? $localeconv[
'thousands_sep'] : $localeconv[
'mon_thousands_sep'];
624 if (self::$thousandsSeparator ==
'') {
626 self::$thousandsSeparator =
',';
630 return self::$thousandsSeparator;
641 self::$thousandsSeparator = $pValue;
652 if (!empty(self::$currencyCode)) {
653 return self::$currencyCode;
655 self::$currencyCode =
'$';
656 $localeconv = localeconv();
657 if (!empty($localeconv[
'currency_symbol'])) {
658 self::$currencyCode = $localeconv[
'currency_symbol'];
660 return self::$currencyCode;
662 if (!empty($localeconv[
'int_curr_symbol'])) {
663 self::$currencyCode = $localeconv[
'int_curr_symbol'];
665 return self::$currencyCode;
668 return self::$currencyCode;
679 self::$currencyCode = $pValue;
691 self::buildCharacterSets();
694 if (strpos($pValue,
'') ===
false) {
698 foreach (self::$SYLKCharacters as $k => $v) {
699 $pValue = str_replace($k, $v, $pValue);
715 if (is_numeric($value)) {
720 return (is_numeric(substr($value, 0, strlen($v)))) ? $v : $value;
static controlCharacterPHP2OOXML($value)
Convert from PHP control character to OpenXML escaped control character.
static sanitizeUTF8($value)
Try to sanitize UTF8, stripping invalid byte sequences.
static controlCharacterOOXML2PHP($value)
Convert from OpenXML escaped control character to PHP control character.
static testStringAsNumeric($value)
Retrieve any leading numeric part of a string, or return the full string if no leading numeric (handl...
static strToTitle($pValue)
Convert a UTF-8 encoded string to title/proper case (uppercase every first character in each word...
static convertToNumberIfFraction(&$operand)
Identify whether a string contains a fractional numeric value, and convert it to a numeric if it is...
static countCharacters($value, $enc='UTF-8')
Get character count.
static SYLKtoUTF8($pValue)
Convert SYLK encoded string to UTF-8.
static $controlCharacters
static formatNumber($value)
Formats a numeric value as a string for output in various output writers forcing point as decimal sep...
static isUTF8($value)
Check if a string contains UTF8 data.
static UTF8toBIFF8UnicodeShort($value, $arrcRuns=[])
Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length) Writes the string using ...
static setThousandsSeparator($pValue)
Set the thousands separator.
static getIsIconvEnabled()
Get whether iconv extension is available.
static buildControlCharacters()
Build control characters array.
static setDecimalSeparator($pValue)
Set the decimal separator.
const STRING_REGEXP_FRACTION
Constants.
static mbStrSplit($string)
static getCurrencyCode()
Get the currency code.
static strToUpper($pValue)
Convert a UTF-8 encoded string to upper case.
static buildSYLKCharacters()
Build SYLK characters array.
static $thousandsSeparator
static UTF8toBIFF8UnicodeLong($value)
Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length) Writes the string using...
static strCaseReverse($pValue)
Reverse the case of a string, so that all uppercase characters become lowercase and all lowercase cha...
static convertEncoding($value, $to, $from)
Convert string from one encoding to another.
static buildCharacterSets()
static strToLower($pValue)
Convert a UTF-8 encoded string to lower case.
static getInstance(?Spreadsheet $spreadsheet=null)
Get an instance of this class.
static setCurrencyCode($pValue)
Set the currency code.
static substring($pValue, $pStart, $pLength=0)
Get a substring of a UTF-8 encoded string.
static getThousandsSeparator()
Get the thousands separator.
static getDecimalSeparator()
Get the decimal separator.