ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
PHPExcel_Shared_String Class Reference
+ Collaboration diagram for PHPExcel_Shared_String:

Static Public Member Functions

static getIsMbstringEnabled ()
 Get whether mbstring extension is available. More...
 
static getIsIconvEnabled ()
 Get whether iconv extension is available. More...
 
static buildCharacterSets ()
 
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=array())
 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 utf16_decode ($str, $bom_be=TRUE)
 Decode UTF-16 encoded strings. More...
 
static CountCharacters ($value, $enc='UTF-8')
 Get character count. More...
 
static Substring ($pValue='', $pStart=0, $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 mb_is_upper ($char)
 
static mb_str_split ($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 Private Attributes

static $_controlCharacters = array()
 
static $_SYLKCharacters = array()
 SYLK Characters array. More...
 
static $_decimalSeparator
 
static $_thousandsSeparator
 
static $_currencyCode
 
static $_isMbstringEnabled
 
static $_isIconvEnabled
 

Detailed Description

Definition at line 36 of file String.php.

Member Function Documentation

◆ _buildControlCharacters()

static PHPExcel_Shared_String::_buildControlCharacters ( )
staticprivate

Build control characters array.

Definition at line 96 of file String.php.

96  {
97  for ($i = 0; $i <= 31; ++$i) {
98  if ($i != 9 && $i != 10 && $i != 13) {
99  $find = '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_';
100  $replace = chr($i);
101  self::$_controlCharacters[$find] = $replace;
102  }
103  }
104  }

◆ _buildSYLKCharacters()

static PHPExcel_Shared_String::_buildSYLKCharacters ( )
staticprivate

Build SYLK characters array.

Definition at line 109 of file String.php.

References array.

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

◆ buildCharacterSets()

static PHPExcel_Shared_String::buildCharacterSets ( )
static

Definition at line 332 of file String.php.

332  {
333  if(empty(self::$_controlCharacters)) {
334  self::_buildControlCharacters();
335  }
336  if(empty(self::$_SYLKCharacters)) {
337  self::_buildSYLKCharacters();
338  }
339  }

◆ ControlCharacterOOXML2PHP()

static PHPExcel_Shared_String::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 355 of file String.php.

Referenced by PHPExcel_Reader_Excel2007\_parseRichText(), and PHPExcel_Reader_Excel2007\load().

355  {
356  return str_replace( array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value );
357  }
+ Here is the caller graph for this function:

◆ ControlCharacterPHP2OOXML()

static PHPExcel_Shared_String::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 373 of file String.php.

Referenced by PHPExcel_Writer_Excel2007_Chart\_writeCatAx(), PHPExcel_Writer_Excel2007_Worksheet\_writeCell(), PHPExcel_Writer_Excel2007_Chart\_writeValAx(), PHPExcel_Writer_Excel2007_StringTable\writeRichText(), PHPExcel_Writer_Excel2007_StringTable\writeRichTextForCharts(), and PHPExcel_Writer_Excel2007_StringTable\writeStringTable().

373  {
374  return str_replace( array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value );
375  }
+ Here is the caller graph for this function:

◆ ConvertEncoding()

static PHPExcel_Shared_String::ConvertEncoding (   $value,
  $to,
  $from 
)
static

Convert string from one encoding to another.

First try mbstring, then iconv, finally strlen

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 493 of file String.php.

Referenced by PHPExcel_Reader_Excel2003XML\_convertStringEncoding(), PHPExcel_Reader_Excel5\_decodeCodepage(), PHPExcel_Reader_Excel5\_encodeUTF16(), PHPExcel_Reader_Excel5\_readDocumentSummaryInformation(), PHPExcel_Reader_Excel5\_readSummaryInformation(), PHPExcel_Writer_Excel5_Worksheet\_writeUrlInternal(), and PHPExcel_Reader_CSV\loadIntoExisting().

494  {
495  if (self::getIsIconvEnabled()) {
496  return iconv($from, $to, $value);
497  }
498 
499  if (self::getIsMbstringEnabled()) {
500  return mb_convert_encoding($value, $to, $from);
501  }
502 
503  if($from == 'UTF-16LE'){
504  return self::utf16_decode($value, false);
505  }else if($from == 'UTF-16BE'){
506  return self::utf16_decode($value);
507  }
508  // else, no conversion
509  return $value;
510  }
+ Here is the caller graph for this function:

◆ convertToNumberIfFraction()

static PHPExcel_Shared_String::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
boolean

Definition at line 671 of file String.php.

References PHPExcel_Calculation\getInstance().

Referenced by PHPExcel_Calculation\_validateBinaryOperand(), PHPExcel_Shared_JAMA_Matrix\arrayRightDivide(), PHPExcel_Shared_JAMA_Matrix\arrayTimesEquals(), PHPExcel_Shared_JAMA_Matrix\minusEquals(), PHPExcel_Shared_JAMA_Matrix\plusEquals(), and PHPExcel_Shared_JAMA_Matrix\power().

671  {
672  if (preg_match('/^'.self::STRING_REGEXP_FRACTION.'$/i', $operand, $match)) {
673  $sign = ($match[1] == '-') ? '-' : '+';
674  $fractionFormula = '='.$sign.$match[2].$sign.$match[3];
675  $operand = PHPExcel_Calculation::getInstance()->_calculateFormulaValue($fractionFormula);
676  return true;
677  }
678  return false;
679  } // function convertToNumberIfFraction()
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CountCharacters()

static PHPExcel_Shared_String::CountCharacters (   $value,
  $enc = 'UTF-8' 
)
static

Get character count.

First try mbstring, then iconv, finally strlen

Parameters
string$value
string$encEncoding
Returns
int Character count

Definition at line 550 of file String.php.

Referenced by PHPExcel_Worksheet\_checkSheetCodeName(), PHPExcel_Worksheet\_checkSheetTitle(), PHPExcel_Reader_Excel5\_readLabelSst(), PHPExcel_Writer_Excel5_Worksheet\_writeUrlInternal(), PHPExcel_Writer_Excel5_Worksheet\close(), PHPExcel_Shared_Font\getTextWidthPixelsApprox(), PHPExcel_Calculation_TextData\SEARCHINSENSITIVE(), PHPExcel_Calculation_TextData\SEARCHSENSITIVE(), PHPExcel_Worksheet\setCodeName(), and PHPExcel_Worksheet\setTitle().

551  {
552  if (self::getIsMbstringEnabled()) {
553  return mb_strlen($value, $enc);
554  }
555 
556  if (self::getIsIconvEnabled()) {
557  return iconv_strlen($value, $enc);
558  }
559 
560  // else strlen
561  return strlen($value);
562  }
+ Here is the caller graph for this function:

◆ FormatNumber()

static PHPExcel_Shared_String::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 416 of file String.php.

Referenced by PHPExcel_Writer_HTML\_setMargins(), PHPExcel_Writer_Excel2007_Worksheet\_writeCell(), PHPExcel_Writer_Excel2007_Worksheet\_writeCols(), PHPExcel_Writer_Excel2007_Worksheet\_writePageMargins(), PHPExcel_Writer_Excel2007_Worksheet\_writeSheetData(), and PHPExcel_Writer_Excel2007_Worksheet\_writeSheetFormatPr().

416  {
417  if (is_float($value)) {
418  return str_replace(',', '.', $value);
419  }
420  return (string) $value;
421  }
+ Here is the caller graph for this function:

◆ getCurrencyCode()

static PHPExcel_Shared_String::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 751 of file String.php.

Referenced by PHPExcel_Cell_AdvancedValueBinder\bindValue(), PHPExcel_Style_NumberFormat\toFormattedString(), and PHPExcel_Calculation_TextData\VALUE().

752  {
753  if (!isset(self::$_currencyCode)) {
754  $localeconv = localeconv();
755  self::$_currencyCode = ($localeconv['currency_symbol'] != '')
756  ? $localeconv['currency_symbol'] : $localeconv['int_curr_symbol'];
757 
758  if (self::$_currencyCode == '') {
759  // Default to $
760  self::$_currencyCode = '$';
761  }
762  }
763  return self::$_currencyCode;
764  }
+ Here is the caller graph for this function:

◆ getDecimalSeparator()

static PHPExcel_Shared_String::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 687 of file String.php.

Referenced by PHPExcel_Cell_AdvancedValueBinder\bindValue(), and PHPExcel_Style_NumberFormat\toFormattedString().

688  {
689  if (!isset(self::$_decimalSeparator)) {
690  $localeconv = localeconv();
691  self::$_decimalSeparator = ($localeconv['decimal_point'] != '')
692  ? $localeconv['decimal_point'] : $localeconv['mon_decimal_point'];
693 
694  if (self::$_decimalSeparator == '') {
695  // Default to .
696  self::$_decimalSeparator = '.';
697  }
698  }
699  return self::$_decimalSeparator;
700  }
+ Here is the caller graph for this function:

◆ getIsIconvEnabled()

static PHPExcel_Shared_String::getIsIconvEnabled ( )
static

Get whether iconv extension is available.

Returns
boolean

Definition at line 293 of file String.php.

References defined.

294  {
295  if (isset(self::$_isIconvEnabled)) {
296  return self::$_isIconvEnabled;
297  }
298 
299  // Fail if iconv doesn't exist
300  if (!function_exists('iconv')) {
301  self::$_isIconvEnabled = false;
302  return false;
303  }
304 
305  // Sometimes iconv is not working, and e.g. iconv('UTF-8', 'UTF-16LE', 'x') just returns false,
306  if (!@iconv('UTF-8', 'UTF-16LE', 'x')) {
307  self::$_isIconvEnabled = false;
308  return false;
309  }
310 
311  // Sometimes iconv_substr('A', 0, 1, 'UTF-8') just returns false in PHP 5.2.0
312  // we cannot use iconv in that case either (http://bugs.php.net/bug.php?id=37773)
313  if (!@iconv_substr('A', 0, 1, 'UTF-8')) {
314  self::$_isIconvEnabled = false;
315  return false;
316  }
317 
318  // CUSTOM: IBM AIX iconv() does not work
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) )
322  {
323  self::$_isIconvEnabled = false;
324  return false;
325  }
326 
327  // If we reach here no problems were detected with iconv
328  self::$_isIconvEnabled = true;
329  return true;
330  }
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27

◆ getIsMbstringEnabled()

static PHPExcel_Shared_String::getIsMbstringEnabled ( )
static

Get whether mbstring extension is available.

Returns
boolean

Definition at line 276 of file String.php.

277  {
278  if (isset(self::$_isMbstringEnabled)) {
279  return self::$_isMbstringEnabled;
280  }
281 
282  self::$_isMbstringEnabled = function_exists('mb_convert_encoding') ?
283  true : false;
284 
285  return self::$_isMbstringEnabled;
286  }

◆ getThousandsSeparator()

static PHPExcel_Shared_String::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 719 of file String.php.

Referenced by PHPExcel_Cell_AdvancedValueBinder\bindValue(), PHPExcel_Style_NumberFormat\toFormattedString(), and PHPExcel_Calculation_TextData\VALUE().

720  {
721  if (!isset(self::$_thousandsSeparator)) {
722  $localeconv = localeconv();
723  self::$_thousandsSeparator = ($localeconv['thousands_sep'] != '')
724  ? $localeconv['thousands_sep'] : $localeconv['mon_thousands_sep'];
725 
726  if (self::$_thousandsSeparator == '') {
727  // Default to .
728  self::$_thousandsSeparator = ',';
729  }
730  }
731  return self::$_thousandsSeparator;
732  }
+ Here is the caller graph for this function:

◆ IsUTF8()

static PHPExcel_Shared_String::IsUTF8 (   $value = '')
static

Check if a string contains UTF8 data.

Parameters
string$value
Returns
boolean

Definition at line 405 of file String.php.

405  {
406  return $value === '' || preg_match('/^./su', $value) === 1;
407  }

◆ mb_is_upper()

static PHPExcel_Shared_String::mb_is_upper (   $char)
static

Definition at line 629 of file String.php.

630  {
631  return mb_strtolower($char, "UTF-8") != $char;
632  }

◆ mb_str_split()

static PHPExcel_Shared_String::mb_str_split (   $string)
static

Definition at line 634 of file String.php.

635  {
636  # Split at all position not after the start: ^
637  # and not before the end: $
638  return preg_split('/(?<!^)(?!$)/u', $string );
639  }

◆ SanitizeUTF8()

static PHPExcel_Shared_String::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 383 of file String.php.

Referenced by PHPExcel_Cell_AdvancedValueBinder\bindValue(), and PHPExcel_Cell_DefaultValueBinder\bindValue().

384  {
385  if (self::getIsIconvEnabled()) {
386  $value = @iconv('UTF-8', 'UTF-8', $value);
387  return $value;
388  }
389 
390  if (self::getIsMbstringEnabled()) {
391  $value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
392  return $value;
393  }
394 
395  // else, no conversion
396  return $value;
397  }
+ Here is the caller graph for this function:

◆ setCurrencyCode()

static PHPExcel_Shared_String::setCurrencyCode (   $pValue = '$')
static

Set the currency code.

Only used by PHPExcel_Style_NumberFormat::toFormattedString() to format output by PHPExcel_Writer_HTML and PHPExcel_Writer_PDF

Parameters
string$pValueCharacter for currency code

Definition at line 772 of file String.php.

Referenced by AdvancedValueBinderTest\testCurrency().

773  {
774  self::$_currencyCode = $pValue;
775  }
+ Here is the caller graph for this function:

◆ setDecimalSeparator()

static PHPExcel_Shared_String::setDecimalSeparator (   $pValue = '.')
static

Set the decimal separator.

Only used by PHPExcel_Style_NumberFormat::toFormattedString() to format output by PHPExcel_Writer_HTML and PHPExcel_Writer_PDF

Parameters
string$pValueCharacter for decimal separator

Definition at line 708 of file String.php.

Referenced by NumberFormatTest\setUp(), and AdvancedValueBinderTest\testCurrency().

709  {
710  self::$_decimalSeparator = $pValue;
711  }
+ Here is the caller graph for this function:

◆ setThousandsSeparator()

static PHPExcel_Shared_String::setThousandsSeparator (   $pValue = ',')
static

Set the thousands separator.

Only used by PHPExcel_Style_NumberFormat::toFormattedString() to format output by PHPExcel_Writer_HTML and PHPExcel_Writer_PDF

Parameters
string$pValueCharacter for thousands separator

Definition at line 740 of file String.php.

Referenced by NumberFormatTest\setUp(), and AdvancedValueBinderTest\testCurrency().

741  {
742  self::$_thousandsSeparator = $pValue;
743  }
+ Here is the caller graph for this function:

◆ StrCaseReverse()

static PHPExcel_Shared_String::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 648 of file String.php.

Referenced by PHPExcel_Calculation\strcmpLowercaseFirst().

649  {
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');
655  } else {
656  $character = mb_strtoupper($character, 'UTF-8');
657  }
658  }
659  return implode('', $characters);
660  }
661  return strtolower($pValue) ^ strtoupper($pValue) ^ $pValue;
662  }
+ Here is the caller graph for this function:

◆ StrToLower()

static PHPExcel_Shared_String::StrToLower (   $pValue = '')
static

Convert a UTF-8 encoded string to lower case.

Parameters
string$pValueUTF-8 encoded string
Returns
string

Definition at line 606 of file String.php.

Referenced by PHPExcel_Calculation_TextData\LOWERCASE().

607  {
608  if (function_exists('mb_convert_case')) {
609  return mb_convert_case($pValue, MB_CASE_LOWER, "UTF-8");
610  }
611  return strtolower($pValue);
612  }
+ Here is the caller graph for this function:

◆ StrToTitle()

static PHPExcel_Shared_String::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 621 of file String.php.

Referenced by PHPExcel_Calculation_TextData\PROPERCASE().

622  {
623  if (function_exists('mb_convert_case')) {
624  return mb_convert_case($pValue, MB_CASE_TITLE, "UTF-8");
625  }
626  return ucwords($pValue);
627  }
+ Here is the caller graph for this function:

◆ StrToUpper()

static PHPExcel_Shared_String::StrToUpper (   $pValue = '')
static

Convert a UTF-8 encoded string to upper case.

Parameters
string$pValueUTF-8 encoded string
Returns
string

Definition at line 592 of file String.php.

Referenced by PHPExcel_Calculation_TextData\UPPERCASE().

593  {
594  if (function_exists('mb_convert_case')) {
595  return mb_convert_case($pValue, MB_CASE_UPPER, "UTF-8");
596  }
597  return strtoupper($pValue);
598  }
+ Here is the caller graph for this function:

◆ Substring()

static PHPExcel_Shared_String::Substring (   $pValue = '',
  $pStart = 0,
  $pLength = 0 
)
static

Get a substring of a UTF-8 encoded string.

First try mbstring, then iconv, finally strlen

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

Definition at line 572 of file String.php.

Referenced by PHPExcel_Worksheet\_checkSheetCodeName(), PHPExcel_Reader_Excel5\_readLabelSst(), PHPExcel_Cell_DataType\checkString(), PHPExcel_Worksheet\setCodeName(), and PHPExcel_Worksheet\setTitle().

573  {
574  if (self::getIsMbstringEnabled()) {
575  return mb_substr($pValue, $pStart, $pLength, 'UTF-8');
576  }
577 
578  if (self::getIsIconvEnabled()) {
579  return iconv_substr($pValue, $pStart, $pLength, 'UTF-8');
580  }
581 
582  // else substr
583  return substr($pValue, $pStart, $pLength);
584  }
+ Here is the caller graph for this function:

◆ SYLKtoUTF8()

static PHPExcel_Shared_String::SYLKtoUTF8 (   $pValue = '')
static

Convert SYLK encoded string to UTF-8.

Parameters
string$pValue
Returns
string UTF-8 encoded string

Definition at line 783 of file String.php.

Referenced by PHPExcel_Reader_SYLK\listWorksheetInfo(), and PHPExcel_Reader_SYLK\loadIntoExisting().

784  {
785  // If there is no escape character in the string there is nothing to do
786  if (strpos($pValue, '') === false) {
787  return $pValue;
788  }
789 
790  foreach (self::$_SYLKCharacters as $k => $v) {
791  $pValue = str_replace($k, $v, $pValue);
792  }
793 
794  return $pValue;
795  }
+ Here is the caller graph for this function:

◆ testStringAsNumeric()

static PHPExcel_Shared_String::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 804 of file String.php.

Referenced by PHPExcel_Calculation_DateTime\DATE().

805  {
806  if (is_numeric($value))
807  return $value;
808  $v = floatval($value);
809  return (is_numeric(substr($value, 0, strlen($v)))) ? $v : $value;
810  }
+ Here is the caller graph for this function:

◆ utf16_decode()

static PHPExcel_Shared_String::utf16_decode (   $str,
  $bom_be = TRUE 
)
static

Decode UTF-16 encoded strings.

Can handle both BOM'ed data and un-BOM'ed data. Assumes Big-Endian byte order if no BOM is available. This function was taken from http://php.net/manual/en/function.utf8-decode.php and $bom_be parameter added.

Parameters
string$strUTF-16 encoded data to decode.
Returns
string UTF-8 / ISO encoded data. public
Version
0.2 / 2010-05-13
Author
Rasmus Andersson http://rasmusandersson.se/
vadik56

Definition at line 527 of file String.php.

527  {
528  if( strlen($str) < 2 ) return $str;
529  $c0 = ord($str{0});
530  $c1 = ord($str{1});
531  if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
532  elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; }
533  $len = strlen($str);
534  $newstr = '';
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);
539  }
540  return $newstr;
541  }

◆ UTF8toBIFF8UnicodeLong()

static PHPExcel_Shared_String::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 469 of file String.php.

References $data.

Referenced by PHPExcel_Writer_Excel5_Worksheet\_writeCFRule(), PHPExcel_Writer_Excel5_Worksheet\_writeDataValidity(), PHPExcel_Writer_Excel5_Worksheet\_writeFooter(), PHPExcel_Writer_Excel5_Worksheet\_writeHeader(), PHPExcel_Writer_Excel5_Worksheet\_writeLabelSst(), PHPExcel_Writer_Excel5_Worksheet\_writeRangeProtection(), and PHPExcel_Writer_Excel5_Worksheet\_writeStringRecord().

470  {
471  // character count
472  $ln = self::CountCharacters($value, 'UTF-8');
473 
474  // option flags
475  $opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
476  0x0001 : 0x0000;
477 
478  // characters
479  $chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8');
480 
481  $data = pack('vC', $ln, $opt) . $chars;
482  return $data;
483  }
+ Here is the caller graph for this function:

◆ UTF8toBIFF8UnicodeShort()

static PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort (   $value,
  $arrcRuns = array() 
)
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[]$arrcRuns Details of rich text runs in $value
Returns
string

Definition at line 434 of file String.php.

References $data.

Referenced by PHPExcel_Writer_Excel5_Workbook\_calcSheetOffsets(), PHPExcel_Writer_Excel5_Parser\_convertString(), PHPExcel_Writer_Excel5_Worksheet\_writeRichTextString(), and PHPExcel_Writer_Excel5_Font\writeFont().

435  {
436  // character count
437  $ln = self::CountCharacters($value, 'UTF-8');
438  // option flags
439  if(empty($arrcRuns)){
440  $opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
441  0x0001 : 0x0000;
442  $data = pack('CC', $ln, $opt);
443  // characters
444  $data .= self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8');
445  }
446  else {
447  $data = pack('vC', $ln, 0x09);
448  $data .= pack('v', count($arrcRuns));
449  // characters
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']);
454  }
455  }
456  return $data;
457  }
+ Here is the caller graph for this function:

Field Documentation

◆ $_controlCharacters

PHPExcel_Shared_String::$_controlCharacters = array()
staticprivate

Definition at line 49 of file String.php.

◆ $_currencyCode

PHPExcel_Shared_String::$_currencyCode
staticprivate

Definition at line 77 of file String.php.

◆ $_decimalSeparator

PHPExcel_Shared_String::$_decimalSeparator
staticprivate

Definition at line 63 of file String.php.

◆ $_isIconvEnabled

PHPExcel_Shared_String::$_isIconvEnabled
staticprivate

Definition at line 91 of file String.php.

◆ $_isMbstringEnabled

PHPExcel_Shared_String::$_isMbstringEnabled
staticprivate

Definition at line 84 of file String.php.

◆ $_SYLKCharacters

PHPExcel_Shared_String::$_SYLKCharacters = array()
staticprivate

SYLK Characters array.

$var array

Definition at line 56 of file String.php.

◆ $_thousandsSeparator

PHPExcel_Shared_String::$_thousandsSeparator
staticprivate

Definition at line 70 of file String.php.

◆ STRING_REGEXP_FRACTION

const PHPExcel_Shared_String::STRING_REGEXP_FRACTION = '(-?)(\d+)\s+(\d+\/\d+)'

Constants.

Regular Expressions

Definition at line 41 of file String.php.


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