ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Shared\StringHelper Class Reference
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Shared\StringHelper:

Static Public Member Functions

static getIsIconvEnabled ()
 Get whether iconv extension is available. More...
 
static controlCharacterOOXML2PHP ($value)
 Convert from OpenXML escaped control character to PHP control character. More...
 
static controlCharacterPHP2OOXML ($value)
 Convert from PHP control character to OpenXML escaped control character. More...
 
static sanitizeUTF8 ($value)
 Try to sanitize UTF8, stripping invalid byte sequences. More...
 
static isUTF8 ($value)
 Check if a string contains UTF8 data. More...
 
static formatNumber ($value)
 Formats a numeric value as a string for output in various output writers forcing point as decimal separator in case locale is other than English. More...
 
static UTF8toBIFF8UnicodeShort ($value, $arrcRuns=[])
 Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length) Writes the string using uncompressed notation, no rich text, no Asian phonetics If mbstring extension is not available, ASCII is assumed, and compressed notation is used although this will give wrong results for non-ASCII strings see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. More...
 
static UTF8toBIFF8UnicodeLong ($value)
 Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length) Writes the string using uncompressed notation, no rich text, no Asian phonetics If mbstring extension is not available, ASCII is assumed, and compressed notation is used although this will give wrong results for non-ASCII strings see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. More...
 
static convertEncoding ($value, $to, $from)
 Convert string from one encoding to another. More...
 
static countCharacters ($value, $enc='UTF-8')
 Get character count. More...
 
static substring ($pValue, $pStart, $pLength=0)
 Get a substring of a UTF-8 encoded string. More...
 
static strToUpper ($pValue)
 Convert a UTF-8 encoded string to upper case. More...
 
static strToLower ($pValue)
 Convert a UTF-8 encoded string to lower case. More...
 
static strToTitle ($pValue)
 Convert a UTF-8 encoded string to title/proper case (uppercase every first character in each word, lower case all other characters). More...
 
static mbIsUpper ($char)
 
static mbStrSplit ($string)
 
static strCaseReverse ($pValue)
 Reverse the case of a string, so that all uppercase characters become lowercase and all lowercase characters become uppercase. More...
 
static convertToNumberIfFraction (&$operand)
 Identify whether a string contains a fractional numeric value, and convert it to a numeric if it is. More...
 
static getDecimalSeparator ()
 Get the decimal separator. More...
 
static setDecimalSeparator ($pValue)
 Set the decimal separator. More...
 
static getThousandsSeparator ()
 Get the thousands separator. More...
 
static setThousandsSeparator ($pValue)
 Set the thousands separator. More...
 
static getCurrencyCode ()
 Get the currency code. More...
 
static setCurrencyCode ($pValue)
 Set the currency code. More...
 
static SYLKtoUTF8 ($pValue)
 Convert SYLK encoded string to UTF-8. More...
 
static testStringAsNumeric ($value)
 Retrieve any leading numeric part of a string, or return the full string if no leading numeric (handles basic integer or float, but not exponent or non decimal). More...
 

Data Fields

const STRING_REGEXP_FRACTION = '(-?)(\d+)\s+(\d+\/\d+)'
 Constants
More...
 

Static Private Member Functions

static buildControlCharacters ()
 Build control characters array. More...
 
static buildSYLKCharacters ()
 Build SYLK characters array. More...
 
static buildCharacterSets ()
 

Static Private Attributes

static $controlCharacters = []
 
static $SYLKCharacters = []
 
static $decimalSeparator
 
static $thousandsSeparator
 
static $currencyCode
 
static $isIconvEnabled
 
static $iconvOptions = '//IGNORE//TRANSLIT'
 

Detailed Description

Definition at line 7 of file StringHelper.php.

Member Function Documentation

◆ buildCharacterSets()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::buildCharacterSets ( )
staticprivate

Definition at line 275 of file StringHelper.php.

275 : void
276 {
277 if (empty(self::$controlCharacters)) {
279 }
280
281 if (empty(self::$SYLKCharacters)) {
283 }
284 }
static buildControlCharacters()
Build control characters array.
static buildSYLKCharacters()
Build SYLK characters array.

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\buildControlCharacters(), and PhpOffice\PhpSpreadsheet\Shared\StringHelper\buildSYLKCharacters().

Referenced by PhpOffice\PhpSpreadsheet\Shared\StringHelper\controlCharacterOOXML2PHP(), PhpOffice\PhpSpreadsheet\Shared\StringHelper\controlCharacterPHP2OOXML(), and PhpOffice\PhpSpreadsheet\Shared\StringHelper\SYLKtoUTF8().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildControlCharacters()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::buildControlCharacters ( )
staticprivate

Build control characters array.

Definition at line 66 of file StringHelper.php.

66 : void
67 {
68 for ($i = 0; $i <= 31; ++$i) {
69 if ($i != 9 && $i != 10 && $i != 13) {
70 $find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
71 $replace = chr($i);
72 self::$controlCharacters[$find] = $replace;
73 }
74 }
75 }
$i
Definition: disco.tpl.php:19

References $i.

Referenced by PhpOffice\PhpSpreadsheet\Shared\StringHelper\buildCharacterSets().

+ Here is the caller graph for this function:

◆ buildSYLKCharacters()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::buildSYLKCharacters ( )
staticprivate

Build SYLK characters array.

Definition at line 80 of file StringHelper.php.

80 : void
81 {
82 self::$SYLKCharacters = [
83 "\x1B 0" => chr(0),
84 "\x1B 1" => chr(1),
85 "\x1B 2" => chr(2),
86 "\x1B 3" => chr(3),
87 "\x1B 4" => chr(4),
88 "\x1B 5" => chr(5),
89 "\x1B 6" => chr(6),
90 "\x1B 7" => chr(7),
91 "\x1B 8" => chr(8),
92 "\x1B 9" => chr(9),
93 "\x1B :" => chr(10),
94 "\x1B ;" => chr(11),
95 "\x1B <" => chr(12),
96 "\x1B =" => chr(13),
97 "\x1B >" => chr(14),
98 "\x1B ?" => chr(15),
99 "\x1B!0" => chr(16),
100 "\x1B!1" => chr(17),
101 "\x1B!2" => chr(18),
102 "\x1B!3" => chr(19),
103 "\x1B!4" => chr(20),
104 "\x1B!5" => chr(21),
105 "\x1B!6" => chr(22),
106 "\x1B!7" => chr(23),
107 "\x1B!8" => chr(24),
108 "\x1B!9" => chr(25),
109 "\x1B!:" => chr(26),
110 "\x1B!;" => chr(27),
111 "\x1B!<" => chr(28),
112 "\x1B!=" => chr(29),
113 "\x1B!>" => chr(30),
114 "\x1B!?" => chr(31),
115 "\x1B'?" => chr(127),
116 "\x1B(0" => '€', // 128 in CP1252
117 "\x1B(2" => '‚', // 130 in CP1252
118 "\x1B(3" => 'ƒ', // 131 in CP1252
119 "\x1B(4" => '„', // 132 in CP1252
120 "\x1B(5" => '…', // 133 in CP1252
121 "\x1B(6" => '†', // 134 in CP1252
122 "\x1B(7" => '‡', // 135 in CP1252
123 "\x1B(8" => 'ˆ', // 136 in CP1252
124 "\x1B(9" => '‰', // 137 in CP1252
125 "\x1B(:" => 'Š', // 138 in CP1252
126 "\x1B(;" => '‹', // 139 in CP1252
127 "\x1BNj" => 'Œ', // 140 in CP1252
128 "\x1B(>" => 'Ž', // 142 in CP1252
129 "\x1B)1" => '‘', // 145 in CP1252
130 "\x1B)2" => '’', // 146 in CP1252
131 "\x1B)3" => '“', // 147 in CP1252
132 "\x1B)4" => '”', // 148 in CP1252
133 "\x1B)5" => '•', // 149 in CP1252
134 "\x1B)6" => '–', // 150 in CP1252
135 "\x1B)7" => '—', // 151 in CP1252
136 "\x1B)8" => '˜', // 152 in CP1252
137 "\x1B)9" => '™', // 153 in CP1252
138 "\x1B):" => 'š', // 154 in CP1252
139 "\x1B);" => '›', // 155 in CP1252
140 "\x1BNz" => 'œ', // 156 in CP1252
141 "\x1B)>" => 'ž', // 158 in CP1252
142 "\x1B)?" => 'Ÿ', // 159 in CP1252
143 "\x1B*0" => ' ', // 160 in CP1252
144 "\x1BN!" => '¡', // 161 in CP1252
145 "\x1BN\"" => '¢', // 162 in CP1252
146 "\x1BN#" => '£', // 163 in CP1252
147 "\x1BN(" => '¤', // 164 in CP1252
148 "\x1BN%" => '¥', // 165 in CP1252
149 "\x1B*6" => '¦', // 166 in CP1252
150 "\x1BN'" => '§', // 167 in CP1252
151 "\x1BNH " => '¨', // 168 in CP1252
152 "\x1BNS" => '©', // 169 in CP1252
153 "\x1BNc" => 'ª', // 170 in CP1252
154 "\x1BN+" => '«', // 171 in CP1252
155 "\x1B*<" => '¬', // 172 in CP1252
156 "\x1B*=" => '­', // 173 in CP1252
157 "\x1BNR" => '®', // 174 in CP1252
158 "\x1B*?" => '¯', // 175 in CP1252
159 "\x1BN0" => '°', // 176 in CP1252
160 "\x1BN1" => '±', // 177 in CP1252
161 "\x1BN2" => '²', // 178 in CP1252
162 "\x1BN3" => '³', // 179 in CP1252
163 "\x1BNB " => '´', // 180 in CP1252
164 "\x1BN5" => 'µ', // 181 in CP1252
165 "\x1BN6" => '¶', // 182 in CP1252
166 "\x1BN7" => '·', // 183 in CP1252
167 "\x1B+8" => '¸', // 184 in CP1252
168 "\x1BNQ" => '¹', // 185 in CP1252
169 "\x1BNk" => 'º', // 186 in CP1252
170 "\x1BN;" => '»', // 187 in CP1252
171 "\x1BN<" => '¼', // 188 in CP1252
172 "\x1BN=" => '½', // 189 in CP1252
173 "\x1BN>" => '¾', // 190 in CP1252
174 "\x1BN?" => '¿', // 191 in CP1252
175 "\x1BNAA" => 'À', // 192 in CP1252
176 "\x1BNBA" => 'Á', // 193 in CP1252
177 "\x1BNCA" => 'Â', // 194 in CP1252
178 "\x1BNDA" => 'Ã', // 195 in CP1252
179 "\x1BNHA" => 'Ä', // 196 in CP1252
180 "\x1BNJA" => 'Å', // 197 in CP1252
181 "\x1BNa" => 'Æ', // 198 in CP1252
182 "\x1BNKC" => 'Ç', // 199 in CP1252
183 "\x1BNAE" => 'È', // 200 in CP1252
184 "\x1BNBE" => 'É', // 201 in CP1252
185 "\x1BNCE" => 'Ê', // 202 in CP1252
186 "\x1BNHE" => 'Ë', // 203 in CP1252
187 "\x1BNAI" => 'Ì', // 204 in CP1252
188 "\x1BNBI" => 'Í', // 205 in CP1252
189 "\x1BNCI" => 'Î', // 206 in CP1252
190 "\x1BNHI" => 'Ï', // 207 in CP1252
191 "\x1BNb" => 'Ð', // 208 in CP1252
192 "\x1BNDN" => 'Ñ', // 209 in CP1252
193 "\x1BNAO" => 'Ò', // 210 in CP1252
194 "\x1BNBO" => 'Ó', // 211 in CP1252
195 "\x1BNCO" => 'Ô', // 212 in CP1252
196 "\x1BNDO" => 'Õ', // 213 in CP1252
197 "\x1BNHO" => 'Ö', // 214 in CP1252
198 "\x1B-7" => '×', // 215 in CP1252
199 "\x1BNi" => 'Ø', // 216 in CP1252
200 "\x1BNAU" => 'Ù', // 217 in CP1252
201 "\x1BNBU" => 'Ú', // 218 in CP1252
202 "\x1BNCU" => 'Û', // 219 in CP1252
203 "\x1BNHU" => 'Ü', // 220 in CP1252
204 "\x1B-=" => 'Ý', // 221 in CP1252
205 "\x1BNl" => 'Þ', // 222 in CP1252
206 "\x1BN{" => 'ß', // 223 in CP1252
207 "\x1BNAa" => 'à', // 224 in CP1252
208 "\x1BNBa" => 'á', // 225 in CP1252
209 "\x1BNCa" => 'â', // 226 in CP1252
210 "\x1BNDa" => 'ã', // 227 in CP1252
211 "\x1BNHa" => 'ä', // 228 in CP1252
212 "\x1BNJa" => 'å', // 229 in CP1252
213 "\x1BNq" => 'æ', // 230 in CP1252
214 "\x1BNKc" => 'ç', // 231 in CP1252
215 "\x1BNAe" => 'è', // 232 in CP1252
216 "\x1BNBe" => 'é', // 233 in CP1252
217 "\x1BNCe" => 'ê', // 234 in CP1252
218 "\x1BNHe" => 'ë', // 235 in CP1252
219 "\x1BNAi" => 'ì', // 236 in CP1252
220 "\x1BNBi" => 'í', // 237 in CP1252
221 "\x1BNCi" => 'î', // 238 in CP1252
222 "\x1BNHi" => 'ï', // 239 in CP1252
223 "\x1BNs" => 'ð', // 240 in CP1252
224 "\x1BNDn" => 'ñ', // 241 in CP1252
225 "\x1BNAo" => 'ò', // 242 in CP1252
226 "\x1BNBo" => 'ó', // 243 in CP1252
227 "\x1BNCo" => 'ô', // 244 in CP1252
228 "\x1BNDo" => 'õ', // 245 in CP1252
229 "\x1BNHo" => 'ö', // 246 in CP1252
230 "\x1B/7" => '÷', // 247 in CP1252
231 "\x1BNy" => 'ø', // 248 in CP1252
232 "\x1BNAu" => 'ù', // 249 in CP1252
233 "\x1BNBu" => 'ú', // 250 in CP1252
234 "\x1BNCu" => 'û', // 251 in CP1252
235 "\x1BNHu" => 'ü', // 252 in CP1252
236 "\x1B/=" => 'ý', // 253 in CP1252
237 "\x1BN|" => 'þ', // 254 in CP1252
238 "\x1BNHy" => 'ÿ', // 255 in CP1252
239 ];
240 }

Referenced by PhpOffice\PhpSpreadsheet\Shared\StringHelper\buildCharacterSets().

+ Here is the caller graph for this function:

◆ controlCharacterOOXML2PHP()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterOOXML2PHP (   $value)
static

Convert from OpenXML escaped control character to PHP control character.

Excel 2007 team:

That's correct, control characters are stored directly in the shared-strings table. We do encode characters that cannot be represented in XML using the following escape sequence: xHHHH where H represents a hexadecimal character in the character's value... So you could end up with something like x0008 in a string (either in a cell value (<v>) element or in the shared string <t> element.

Parameters
string$valueValue to unescape
Returns
string

Definition at line 301 of file StringHelper.php.

302 {
304
305 return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value);
306 }

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\buildCharacterSets().

+ Here is the call graph for this function:

◆ controlCharacterPHP2OOXML()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML (   $value)
static

Convert from PHP control character to OpenXML escaped control character.

Excel 2007 team:

That's correct, control characters are stored directly in the shared-strings table. We do encode characters that cannot be represented in XML using the following escape sequence: xHHHH where H represents a hexadecimal character in the character's value... So you could end up with something like x0008 in a string (either in a cell value (<v>) element or in the shared string <t> element.

Parameters
string$valueValue to escape
Returns
string

Definition at line 323 of file StringHelper.php.

324 {
326
327 return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value);
328 }

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\buildCharacterSets().

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xlsx\Chart\writeCategoryAxis(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeCellInlineStr(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\StringTable\writeRichText(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\StringTable\writeRichTextForCharts(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\StringTable\writeStringTable(), and PhpOffice\PhpSpreadsheet\Writer\Xlsx\Chart\writeValueAxis().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convertEncoding()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertEncoding (   $value,
  $to,
  $from 
)
static

Convert string from one encoding to another.

Parameters
string$value
string$toEncoding to convert to, e.g. 'UTF-8'
string$fromEncoding to convert from, e.g. 'UTF-16LE'
Returns
string

Definition at line 445 of file StringHelper.php.

446 {
447 if (self::getIsIconvEnabled()) {
448 $result = iconv($from, $to . self::$iconvOptions, $value);
449 if (false !== $result) {
450 return $result;
451 }
452 }
453
454 return mb_convert_encoding($value, $to, $from);
455 }
$result
$from

References $from, and $result.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Xml\canRead(), PhpOffice\PhpSpreadsheet\Reader\Xls\decodeCodepage(), PhpOffice\PhpSpreadsheet\Reader\Xls\encodeUTF16(), PhpOffice\PhpSpreadsheet\Reader\Csv\openFileOrMemory(), PhpOffice\PhpSpreadsheet\Reader\Xls\readDocumentSummaryInformation(), PhpOffice\PhpSpreadsheet\Reader\Xls\readSummaryInformation(), PhpOffice\PhpSpreadsheet\Shared\StringHelper\UTF8toBIFF8UnicodeLong(), PhpOffice\PhpSpreadsheet\Shared\StringHelper\UTF8toBIFF8UnicodeShort(), and PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeUrlInternal().

+ Here is the caller graph for this function:

◆ convertToNumberIfFraction()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction ( $operand)
static

Identify whether a string contains a fractional numeric value, and convert it to a numeric if it is.

Parameters
string$operandstring value to test
Returns
bool

Definition at line 563 of file StringHelper.php.

564 {
565 if (preg_match('/^' . self::STRING_REGEXP_FRACTION . '$/i', $operand, $match)) {
566 $sign = ($match[1] == '-') ? '-' : '+';
567 $fractionFormula = '=' . $sign . $match[2] . $sign . $match[3];
568 $operand = Calculation::getInstance()->_calculateFormulaValue($fractionFormula);
569
570 return true;
571 }
572
573 return false;
574 }
static getInstance(?Spreadsheet $spreadsheet=null)
Get an instance of this class.

References PhpOffice\PhpSpreadsheet\Calculation\Calculation\getInstance().

Referenced by PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix\arrayRightDivide(), PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix\arrayTimesEquals(), PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix\minusEquals(), PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix\plusEquals(), PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix\power(), and PhpOffice\PhpSpreadsheet\Calculation\Calculation\validateBinaryOperand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ countCharacters()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters (   $value,
  $enc = 'UTF-8' 
)
static

◆ formatNumber()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber (   $value)
static

Formats a numeric value as a string for output in various output writers forcing point as decimal separator in case locale is other than English.

Parameters
mixed$value
Returns
string

Definition at line 370 of file StringHelper.php.

371 {
372 if (is_float($value)) {
373 return str_replace(',', '.', $value);
374 }
375
376 return (string) $value;
377 }

Referenced by PhpOffice\PhpSpreadsheet\Writer\Html\generatePageDeclarations(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeCellFormula(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeCols(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style\writeFont(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writePageMargins(), PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeSheetData(), and PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet\writeSheetFormatPr().

+ Here is the caller graph for this function:

◆ getCurrencyCode()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::getCurrencyCode ( )
static

Get the currency code.

If it has not yet been set explicitly, try to obtain the symbol information from locale.

Returns
string

Definition at line 650 of file StringHelper.php.

651 {
652 if (!empty(self::$currencyCode)) {
653 return self::$currencyCode;
654 }
655 self::$currencyCode = '$';
656 $localeconv = localeconv();
657 if (!empty($localeconv['currency_symbol'])) {
658 self::$currencyCode = $localeconv['currency_symbol'];
659
660 return self::$currencyCode;
661 }
662 if (!empty($localeconv['int_curr_symbol'])) {
663 self::$currencyCode = $localeconv['int_curr_symbol'];
664
665 return self::$currencyCode;
666 }
667
668 return self::$currencyCode;
669 }

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\$currencyCode.

Referenced by PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder\bindValue(), PhpOffice\PhpSpreadsheet\Style\NumberFormat\NumberFormatter\format(), and PhpOffice\PhpSpreadsheet\Calculation\TextData\Format\VALUE().

+ Here is the caller graph for this function:

◆ getDecimalSeparator()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::getDecimalSeparator ( )
static

Get the decimal separator.

If it has not yet been set explicitly, try to obtain number formatting information from locale.

Returns
string

Definition at line 584 of file StringHelper.php.

585 {
586 if (!isset(self::$decimalSeparator)) {
587 $localeconv = localeconv();
588 self::$decimalSeparator = ($localeconv['decimal_point'] != '')
589 ? $localeconv['decimal_point'] : $localeconv['mon_decimal_point'];
590
591 if (self::$decimalSeparator == '') {
592 // Default to .
593 self::$decimalSeparator = '.';
594 }
595 }
596
598 }

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\$decimalSeparator.

Referenced by PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder\bindValue(), PhpOffice\PhpSpreadsheet\Calculation\TextData\Format\FIXEDFORMAT(), PhpOffice\PhpSpreadsheet\Style\NumberFormat\NumberFormatter\formatStraightNumericValue(), and PhpOffice\PhpSpreadsheet\Calculation\TextData\Format\NUMBERVALUE().

+ Here is the caller graph for this function:

◆ getIsIconvEnabled()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::getIsIconvEnabled ( )
static

Get whether iconv extension is available.

Returns
bool

Definition at line 247 of file StringHelper.php.

248 {
249 if (isset(self::$isIconvEnabled)) {
251 }
252
253 // Assume no problems with iconv
254 self::$isIconvEnabled = true;
255
256 // Fail if iconv doesn't exist
257 if (!function_exists('iconv')) {
258 self::$isIconvEnabled = false;
259 } elseif (!@iconv('UTF-8', 'UTF-16LE', 'x')) {
260 // Sometimes iconv is not working, and e.g. iconv('UTF-8', 'UTF-16LE', 'x') just returns false,
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)) {
263 // CUSTOM: IBM AIX iconv() does not work
264 self::$isIconvEnabled = false;
265 }
266
267 // Deactivate iconv default options if they fail (as seen on IMB i)
268 if (self::$isIconvEnabled && !@iconv('UTF-8', 'UTF-16LE' . self::$iconvOptions, 'x')) {
269 self::$iconvOptions = '';
270 }
271
273 }

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\$isIconvEnabled.

◆ getThousandsSeparator()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::getThousandsSeparator ( )
static

Get the thousands separator.

If it has not yet been set explicitly, try to obtain number formatting information from locale.

Returns
string

Definition at line 617 of file StringHelper.php.

618 {
619 if (!isset(self::$thousandsSeparator)) {
620 $localeconv = localeconv();
621 self::$thousandsSeparator = ($localeconv['thousands_sep'] != '')
622 ? $localeconv['thousands_sep'] : $localeconv['mon_thousands_sep'];
623
624 if (self::$thousandsSeparator == '') {
625 // Default to .
626 self::$thousandsSeparator = ',';
627 }
628 }
629
631 }

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\$thousandsSeparator.

Referenced by PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder\bindValue(), PhpOffice\PhpSpreadsheet\Calculation\TextData\Format\FIXEDFORMAT(), PhpOffice\PhpSpreadsheet\Style\NumberFormat\NumberFormatter\formatStraightNumericValue(), PhpOffice\PhpSpreadsheet\Calculation\TextData\Format\NUMBERVALUE(), and PhpOffice\PhpSpreadsheet\Calculation\TextData\Format\VALUE().

+ Here is the caller graph for this function:

◆ isUTF8()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::isUTF8 (   $value)
static

Check if a string contains UTF8 data.

Parameters
string$value
Returns
bool

Definition at line 357 of file StringHelper.php.

358 {
359 return $value === '' || preg_match('/^./su', $value) === 1;
360 }

◆ mbIsUpper()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::mbIsUpper (   $char)
static

Definition at line 521 of file StringHelper.php.

522 {
523 return mb_strtolower($char, 'UTF-8') != $char;
524 }

◆ mbStrSplit()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::mbStrSplit (   $string)
static

Definition at line 526 of file StringHelper.php.

527 {
528 // Split at all position not after the start: ^
529 // and not before the end: $
530 return preg_split('/(?<!^)(?!$)/u', $string);
531 }

Referenced by PhpOffice\PhpSpreadsheet\Shared\StringHelper\strCaseReverse().

+ Here is the caller graph for this function:

◆ sanitizeUTF8()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::sanitizeUTF8 (   $value)
static

Try to sanitize UTF8, stripping invalid byte sequences.

Not perfect. Does not surrogate characters.

Parameters
string$value
Returns
string

Definition at line 337 of file StringHelper.php.

338 {
339 if (self::getIsIconvEnabled()) {
340 $value = @iconv('UTF-8', 'UTF-8', $value);
341
342 return $value;
343 }
344
345 $value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
346
347 return $value;
348 }

Referenced by PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder\bindValue(), PhpOffice\PhpSpreadsheet\Cell\StringValueBinder\bindValue(), and PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder\bindValue().

+ Here is the caller graph for this function:

◆ setCurrencyCode()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::setCurrencyCode (   $pValue)
static

Set the currency code.

Only used by NumberFormat::toFormattedString() to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf.

Parameters
string$pValueCharacter for currency code

Definition at line 677 of file StringHelper.php.

677 : void
678 {
679 self::$currencyCode = $pValue;
680 }

◆ setDecimalSeparator()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::setDecimalSeparator (   $pValue)
static

Set the decimal separator.

Only used by NumberFormat::toFormattedString() to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf.

Parameters
string$pValueCharacter for decimal separator

Definition at line 606 of file StringHelper.php.

606 : void
607 {
608 self::$decimalSeparator = $pValue;
609 }

◆ setThousandsSeparator()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::setThousandsSeparator (   $pValue)
static

Set the thousands separator.

Only used by NumberFormat::toFormattedString() to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf.

Parameters
string$pValueCharacter for thousands separator

Definition at line 639 of file StringHelper.php.

639 : void
640 {
641 self::$thousandsSeparator = $pValue;
642 }

◆ strCaseReverse()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::strCaseReverse (   $pValue)
static

Reverse the case of a string, so that all uppercase characters become lowercase and all lowercase characters become uppercase.

Parameters
string$pValueUTF-8 encoded string
Returns
string

Definition at line 541 of file StringHelper.php.

542 {
543 $characters = self::mbStrSplit($pValue);
544 foreach ($characters as &$character) {
545 if (self::mbIsUpper($character)) {
546 $character = mb_strtolower($character, 'UTF-8');
547 } else {
548 $character = mb_strtoupper($character, 'UTF-8');
549 }
550 }
551
552 return implode('', $characters);
553 }

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\mbStrSplit().

Referenced by PhpOffice\PhpSpreadsheet\Calculation\Calculation\strcmpLowercaseFirst().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strToLower()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::strToLower (   $pValue)
static

◆ strToTitle()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::strToTitle (   $pValue)
static

Convert a UTF-8 encoded string to title/proper case (uppercase every first character in each word, lower case all other characters).

Parameters
string$pValueUTF-8 encoded string
Returns
string

Definition at line 516 of file StringHelper.php.

517 {
518 return mb_convert_case($pValue, MB_CASE_TITLE, 'UTF-8');
519 }

Referenced by PhpOffice\PhpSpreadsheet\Calculation\TextData\CaseConvert\proper().

+ Here is the caller graph for this function:

◆ strToUpper()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::strToUpper (   $pValue)
static

◆ substring()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::substring (   $pValue,
  $pStart,
  $pLength = 0 
)
static

Get a substring of a UTF-8 encoded string.

Parameters
string$pValueUTF-8 encoded string
int$pStartStart offset
int$pLengthMaximum number of characters in substring
Returns
string

Definition at line 479 of file StringHelper.php.

480 {
481 return mb_substr($pValue, $pStart, $pLength, 'UTF-8');
482 }

Referenced by PhpOffice\PhpSpreadsheet\Cell\DataType\checkString(), and PhpOffice\PhpSpreadsheet\Reader\Xls\readLabelSst().

+ Here is the caller graph for this function:

◆ SYLKtoUTF8()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::SYLKtoUTF8 (   $pValue)
static

Convert SYLK encoded string to UTF-8.

Parameters
string$pValue
Returns
string UTF-8 encoded string

Definition at line 689 of file StringHelper.php.

690 {
692
693 // If there is no escape character in the string there is nothing to do
694 if (strpos($pValue, '␛') === false) {
695 return $pValue;
696 }
697
698 foreach (self::$SYLKCharacters as $k => $v) {
699 $pValue = str_replace($k, $v, $pValue);
700 }
701
702 return $pValue;
703 }

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\buildCharacterSets().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Slk\listWorksheetInfo(), and PhpOffice\PhpSpreadsheet\Reader\Slk\loadIntoExisting().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testStringAsNumeric()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::testStringAsNumeric (   $value)
static

Retrieve any leading numeric part of a string, or return the full string if no leading numeric (handles basic integer or float, but not exponent or non decimal).

Parameters
string$value
Returns
mixed string or only the leading numeric part of the string

Definition at line 713 of file StringHelper.php.

714 {
715 if (is_numeric($value)) {
716 return $value;
717 }
718 $v = (float) $value;
719
720 return (is_numeric(substr($value, 0, strlen($v)))) ? $v : $value;
721 }

Referenced by PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Date\getDay(), PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Date\getMonth(), and PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Date\getYear().

+ Here is the caller graph for this function:

◆ UTF8toBIFF8UnicodeLong()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong (   $value)
static

Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length) Writes the string using uncompressed notation, no rich text, no Asian phonetics If mbstring extension is not available, ASCII is assumed, and compressed notation is used although this will give wrong results for non-ASCII strings see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect.

2.5.3.

Parameters
string$valueUTF-8 encoded string
Returns
string

Definition at line 425 of file StringHelper.php.

426 {
427 // character count
428 $ln = self::countCharacters($value, 'UTF-8');
429
430 // characters
431 $chars = self::convertEncoding($value, 'UTF-16LE', 'UTF-8');
432
433 return pack('vC', $ln, 0x0001) . $chars;
434 }
static countCharacters($value, $enc='UTF-8')
Get character count.
static convertEncoding($value, $to, $from)
Convert string from one encoding to another.

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\convertEncoding(), and PhpOffice\PhpSpreadsheet\Shared\StringHelper\countCharacters().

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeCFRule(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeDataValidity(), PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook\writeDefinedNameBiff8(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeFooter(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeHeader(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeLabelSst(), PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook\writeNumberFormat(), PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeRangeProtection(), and PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeStringRecord().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UTF8toBIFF8UnicodeShort()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeShort (   $value,
  $arrcRuns = [] 
)
static

Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length) Writes the string using uncompressed notation, no rich text, no Asian phonetics If mbstring extension is not available, ASCII is assumed, and compressed notation is used although this will give wrong results for non-ASCII strings see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect.

2.5.3.

Parameters
string$valueUTF-8 encoded string
mixed[]$arrcRunsDetails of rich text runs in $value
Returns
string

Definition at line 391 of file StringHelper.php.

392 {
393 // character count
394 $ln = self::countCharacters($value, 'UTF-8');
395 // option flags
396 if (empty($arrcRuns)) {
397 $data = pack('CC', $ln, 0x0001);
398 // characters
399 $data .= self::convertEncoding($value, 'UTF-16LE', 'UTF-8');
400 } else {
401 $data = pack('vC', $ln, 0x09);
402 $data .= pack('v', count($arrcRuns));
403 // characters
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']);
408 }
409 }
410
411 return $data;
412 }
$data
Definition: bench.php:6

References $data, PhpOffice\PhpSpreadsheet\Shared\StringHelper\convertEncoding(), and PhpOffice\PhpSpreadsheet\Shared\StringHelper\countCharacters().

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook\calcSheetOffsets(), PhpOffice\PhpSpreadsheet\Writer\Xls\Parser\convertString(), PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook\writeBoundSheet(), PhpOffice\PhpSpreadsheet\Writer\Xls\Font\writeFont(), and PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\writeRichTextString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $controlCharacters

PhpOffice\PhpSpreadsheet\Shared\StringHelper::$controlCharacters = []
staticprivate

Definition at line 19 of file StringHelper.php.

◆ $currencyCode

PhpOffice\PhpSpreadsheet\Shared\StringHelper::$currencyCode
staticprivate

◆ $decimalSeparator

PhpOffice\PhpSpreadsheet\Shared\StringHelper::$decimalSeparator
staticprivate

◆ $iconvOptions

PhpOffice\PhpSpreadsheet\Shared\StringHelper::$iconvOptions = '//IGNORE//TRANSLIT'
staticprivate

Definition at line 61 of file StringHelper.php.

◆ $isIconvEnabled

PhpOffice\PhpSpreadsheet\Shared\StringHelper::$isIconvEnabled
staticprivate

◆ $SYLKCharacters

PhpOffice\PhpSpreadsheet\Shared\StringHelper::$SYLKCharacters = []
staticprivate

Definition at line 26 of file StringHelper.php.

◆ $thousandsSeparator

PhpOffice\PhpSpreadsheet\Shared\StringHelper::$thousandsSeparator
staticprivate

◆ STRING_REGEXP_FRACTION

const PhpOffice\PhpSpreadsheet\Shared\StringHelper::STRING_REGEXP_FRACTION = '(-?)(\d+)\s+(\d+\/\d+)'

Constants

Regular Expressions

Definition at line 12 of file StringHelper.php.


The documentation for this class was generated from the following file: