ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
TextData.php
Go to the documentation of this file.
1<?php
30if (!defined('PHPEXCEL_ROOT')) {
34 define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35 require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36}
37
38
47
48 private static $_invalidChars = Null;
49
50 private static function _uniord($c) {
51 if (ord($c{0}) >=0 && ord($c{0}) <= 127)
52 return ord($c{0});
53 if (ord($c{0}) >= 192 && ord($c{0}) <= 223)
54 return (ord($c{0})-192)*64 + (ord($c{1})-128);
55 if (ord($c{0}) >= 224 && ord($c{0}) <= 239)
56 return (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128);
57 if (ord($c{0}) >= 240 && ord($c{0}) <= 247)
58 return (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128);
59 if (ord($c{0}) >= 248 && ord($c{0}) <= 251)
60 return (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128);
61 if (ord($c{0}) >= 252 && ord($c{0}) <= 253)
62 return (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128);
63 if (ord($c{0}) >= 254 && ord($c{0}) <= 255) //error
65 return 0;
66 } // function _uniord()
67
74 public static function CHARACTER($character) {
76
77 if ((!is_numeric($character)) || ($character < 0)) {
79 }
80
81 if (function_exists('mb_convert_encoding')) {
82 return mb_convert_encoding('&#'.intval($character).';', 'UTF-8', 'HTML-ENTITIES');
83 } else {
84 return chr(intval($character));
85 }
86 }
87
88
95 public static function TRIMNONPRINTABLE($stringValue = '') {
96 $stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
97
98 if (is_bool($stringValue)) {
100 }
101
102 if (self::$_invalidChars == Null) {
103 self::$_invalidChars = range(chr(0),chr(31));
104 }
105
106 if (is_string($stringValue) || is_numeric($stringValue)) {
107 return str_replace(self::$_invalidChars, '', trim($stringValue, "\x00..\x1F"));
108 }
109 return NULL;
110 } // function TRIMNONPRINTABLE()
111
112
119 public static function TRIMSPACES($stringValue = '') {
120 $stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
121 if (is_bool($stringValue)) {
123 }
124
125 if (is_string($stringValue) || is_numeric($stringValue)) {
126 return trim(preg_replace('/ +/',' ',trim($stringValue, ' ')), ' ');
127 }
128 return NULL;
129 } // function TRIMSPACES()
130
131
138 public static function ASCIICODE($characters) {
139 if (($characters === NULL) || ($characters === ''))
142 if (is_bool($characters)) {
144 $characters = (int) $characters;
145 } else {
146 $characters = ($characters) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
147 }
148 }
149
150 $character = $characters;
151 if ((function_exists('mb_strlen')) && (function_exists('mb_substr'))) {
152 if (mb_strlen($characters, 'UTF-8') > 1) { $character = mb_substr($characters, 0, 1, 'UTF-8'); }
153 return self::_uniord($character);
154 } else {
155 if (strlen($characters) > 0) { $character = substr($characters, 0, 1); }
156 return ord($character);
157 }
158 } // function ASCIICODE()
159
160
166 public static function CONCATENATE() {
167 // Return value
168 $returnValue = '';
169
170 // Loop through arguments
171 $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
172 foreach ($aArgs as $arg) {
173 if (is_bool($arg)) {
175 $arg = (int) $arg;
176 } else {
178 }
179 }
180 $returnValue .= $arg;
181 }
182
183 // Return
184 return $returnValue;
185 } // function CONCATENATE()
186
187
200 public static function DOLLAR($value = 0, $decimals = 2) {
202 $decimals = is_null($decimals) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($decimals);
203
204 // Validate parameters
205 if (!is_numeric($value) || !is_numeric($decimals)) {
207 }
208 $decimals = floor($decimals);
209
210 $mask = '$#,##0';
211 if ($decimals > 0) {
212 $mask .= '.' . str_repeat('0',$decimals);
213 } else {
214 $round = pow(10,abs($decimals));
215 if ($value < 0) { $round = 0-$round; }
216 $value = PHPExcel_Calculation_MathTrig::MROUND($value, $round);
217 }
218
220
221 } // function DOLLAR()
222
223
232 public static function SEARCHSENSITIVE($needle,$haystack,$offset=1) {
236
237 if (!is_bool($needle)) {
238 if (is_bool($haystack)) {
240 }
241
242 if (($offset > 0) && (PHPExcel_Shared_String::CountCharacters($haystack) > $offset)) {
243 if (PHPExcel_Shared_String::CountCharacters($needle) == 0) {
244 return $offset;
245 }
246 if (function_exists('mb_strpos')) {
247 $pos = mb_strpos($haystack, $needle, --$offset, 'UTF-8');
248 } else {
249 $pos = strpos($haystack, $needle, --$offset);
250 }
251 if ($pos !== false) {
252 return ++$pos;
253 }
254 }
255 }
257 } // function SEARCHSENSITIVE()
258
259
268 public static function SEARCHINSENSITIVE($needle,$haystack,$offset=1) {
272
273 if (!is_bool($needle)) {
274 if (is_bool($haystack)) {
276 }
277
278 if (($offset > 0) && (PHPExcel_Shared_String::CountCharacters($haystack) > $offset)) {
279 if (PHPExcel_Shared_String::CountCharacters($needle) == 0) {
280 return $offset;
281 }
282 if (function_exists('mb_stripos')) {
283 $pos = mb_stripos($haystack, $needle, --$offset,'UTF-8');
284 } else {
285 $pos = stripos($haystack, $needle, --$offset);
286 }
287 if ($pos !== false) {
288 return ++$pos;
289 }
290 }
291 }
293 } // function SEARCHINSENSITIVE()
294
295
304 public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = FALSE) {
308
309 // Validate parameters
310 if (!is_numeric($value) || !is_numeric($decimals)) {
312 }
313 $decimals = floor($decimals);
314
315 $valueResult = round($value,$decimals);
316 if ($decimals < 0) { $decimals = 0; }
317 if (!$no_commas) {
318 $valueResult = number_format($valueResult,$decimals);
319 }
320
321 return (string) $valueResult;
322 } // function FIXEDFORMAT()
323
324
332 public static function LEFT($value = '', $chars = 1) {
335
336 if ($chars < 0) {
338 }
339
340 if (is_bool($value)) {
342 }
343
344 if (function_exists('mb_substr')) {
345 return mb_substr($value, 0, $chars, 'UTF-8');
346 } else {
347 return substr($value, 0, $chars);
348 }
349 } // function LEFT()
350
351
360 public static function MID($value = '', $start = 1, $chars = null) {
364
365 if (($start < 1) || ($chars < 0)) {
367 }
368
369 if (is_bool($value)) {
371 }
372
373 if (function_exists('mb_substr')) {
374 return mb_substr($value, --$start, $chars, 'UTF-8');
375 } else {
376 return substr($value, --$start, $chars);
377 }
378 } // function MID()
379
380
388 public static function RIGHT($value = '', $chars = 1) {
391
392 if ($chars < 0) {
394 }
395
396 if (is_bool($value)) {
398 }
399
400 if ((function_exists('mb_substr')) && (function_exists('mb_strlen'))) {
401 return mb_substr($value, mb_strlen($value, 'UTF-8') - $chars, $chars, 'UTF-8');
402 } else {
403 return substr($value, strlen($value) - $chars);
404 }
405 } // function RIGHT()
406
407
414 public static function STRINGLENGTH($value = '') {
416
417 if (is_bool($value)) {
419 }
420
421 if (function_exists('mb_strlen')) {
422 return mb_strlen($value, 'UTF-8');
423 } else {
424 return strlen($value);
425 }
426 } // function STRINGLENGTH()
427
428
437 public static function LOWERCASE($mixedCaseString) {
438 $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
439
440 if (is_bool($mixedCaseString)) {
441 $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
442 }
443
444 return PHPExcel_Shared_String::StrToLower($mixedCaseString);
445 } // function LOWERCASE()
446
447
456 public static function UPPERCASE($mixedCaseString) {
457 $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
458
459 if (is_bool($mixedCaseString)) {
460 $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
461 }
462
463 return PHPExcel_Shared_String::StrToUpper($mixedCaseString);
464 } // function UPPERCASE()
465
466
475 public static function PROPERCASE($mixedCaseString) {
476 $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
477
478 if (is_bool($mixedCaseString)) {
479 $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
480 }
481
482 return PHPExcel_Shared_String::StrToTitle($mixedCaseString);
483 } // function PROPERCASE()
484
485
495 public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText) {
500
501 $left = self::LEFT($oldText,$start-1);
502 $right = self::RIGHT($oldText,self::STRINGLENGTH($oldText)-($start+$chars)+1);
503
504 return $left.$newText.$right;
505 } // function REPLACE()
506
507
517 public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0) {
521 $instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance));
522
523 if ($instance == 0) {
524 if(function_exists('mb_str_replace')) {
525 return mb_str_replace($fromText,$toText,$text);
526 } else {
527 return str_replace($fromText,$toText,$text);
528 }
529 } else {
530 $pos = -1;
531 while($instance > 0) {
532 if (function_exists('mb_strpos')) {
533 $pos = mb_strpos($text, $fromText, $pos+1, 'UTF-8');
534 } else {
535 $pos = strpos($text, $fromText, $pos+1);
536 }
537 if ($pos === false) {
538 break;
539 }
540 --$instance;
541 }
542 if ($pos !== false) {
543 if (function_exists('mb_strlen')) {
544 return self::REPLACE($text,++$pos,mb_strlen($fromText, 'UTF-8'),$toText);
545 } else {
546 return self::REPLACE($text,++$pos,strlen($fromText),$toText);
547 }
548 }
549 }
550
551 return $text;
552 } // function SUBSTITUTE()
553
554
561 public static function RETURNSTRING($testValue = '') {
563
564 if (is_string($testValue)) {
565 return $testValue;
566 }
567 return Null;
568 } // function RETURNSTRING()
569
570
578 public static function TEXTFORMAT($value,$format) {
581
582 if ((is_string($value)) && (!is_numeric($value)) && PHPExcel_Shared_Date::isDateTimeFormatCode($format)) {
584 }
585
586 return (string) PHPExcel_Style_NumberFormat::toFormattedString($value,$format);
587 } // function TEXTFORMAT()
588
595 public static function VALUE($value = '') {
597
598 if (!is_numeric($value)) {
599 $numberValue = str_replace(
601 '',
602 trim($value, " \t\n\r\0\x0B" . PHPExcel_Shared_String::getCurrencyCode())
603 );
604 if (is_numeric($numberValue)) {
605 return (float) $numberValue;
606 }
607
610
611 if (strpos($value, ':') !== false) {
612 $timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($value);
613 if ($timeValue !== PHPExcel_Calculation_Functions::VALUE()) {
615 return $timeValue;
616 }
617 }
618 $dateValue = PHPExcel_Calculation_DateTime::DATEVALUE($value);
619 if ($dateValue !== PHPExcel_Calculation_Functions::VALUE()) {
621 return $dateValue;
622 }
624
626 }
627 return (float) $value;
628 }
629
630}
An exception for terminatinating execution or to throw for unit testing.
static DATEVALUE($dateValue=1)
Definition: DateTime.php:481
static TIMEVALUE($timeValue)
Definition: DateTime.php:583
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:662
static setReturnDateType($returnDateType)
Definition: Functions.php:155
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
Definition: Functions.php:598
static MROUND($number, $multiple)
MROUND.
Definition: MathTrig.php:686
static UPPERCASE($mixedCaseString)
UPPERCASE.
Definition: TextData.php:456
static RETURNSTRING($testValue='')
RETURNSTRING.
Definition: TextData.php:561
static CONCATENATE()
CONCATENATE.
Definition: TextData.php:166
static ASCIICODE($characters)
ASCIICODE.
Definition: TextData.php:138
static SEARCHINSENSITIVE($needle, $haystack, $offset=1)
SEARCHINSENSITIVE.
Definition: TextData.php:268
static TRIMNONPRINTABLE($stringValue='')
TRIMNONPRINTABLE.
Definition: TextData.php:95
static RIGHT($value='', $chars=1)
RIGHT.
Definition: TextData.php:388
static FIXEDFORMAT($value, $decimals=2, $no_commas=FALSE)
FIXEDFORMAT.
Definition: TextData.php:304
static CHARACTER($character)
CHARACTER.
Definition: TextData.php:74
static TRIMSPACES($stringValue='')
TRIMSPACES.
Definition: TextData.php:119
static SEARCHSENSITIVE($needle, $haystack, $offset=1)
SEARCHSENSITIVE.
Definition: TextData.php:232
static REPLACE($oldText='', $start=1, $chars=null, $newText)
REPLACE.
Definition: TextData.php:495
static LEFT($value='', $chars=1)
LEFT.
Definition: TextData.php:332
static DOLLAR($value=0, $decimals=2)
DOLLAR.
Definition: TextData.php:200
static TEXTFORMAT($value, $format)
TEXTFORMAT.
Definition: TextData.php:578
static STRINGLENGTH($value='')
STRINGLENGTH.
Definition: TextData.php:414
static LOWERCASE($mixedCaseString)
LOWERCASE.
Definition: TextData.php:437
static PROPERCASE($mixedCaseString)
PROPERCASE.
Definition: TextData.php:475
static MID($value='', $start=1, $chars=null)
MID.
Definition: TextData.php:360
static SUBSTITUTE($text='', $fromText='', $toText='', $instance=0)
SUBSTITUTE.
Definition: TextData.php:517
static VALUE($value='')
VALUE.
Definition: TextData.php:595
static getFALSE()
Return the locale-specific translation of FALSE.
static getTRUE()
Return the locale-specific translation of TRUE.
static isDateTimeFormatCode($pFormatCode='')
Is a given number format code a date/time?
Definition: Date.php:282
static StrToUpper($pValue='')
Convert a UTF-8 encoded string to upper case.
Definition: String.php:592
static CountCharacters($value, $enc='UTF-8')
Get character count.
Definition: String.php:550
static StrToTitle($pValue='')
Convert a UTF-8 encoded string to title/proper case (uppercase every first character in each word,...
Definition: String.php:621
static StrToLower($pValue='')
Convert a UTF-8 encoded string to lower case.
Definition: String.php:606
static getCurrencyCode()
Definition: String.php:751
static getThousandsSeparator()
Get the thousands separator.
Definition: String.php:719
static toFormattedString($value='0', $format=PHPExcel_Style_NumberFormat::FORMAT_GENERAL, $callBack=null)
Convert a value in a pre-defined format to a PHP string.
$text
$mask
Definition: example_042.php:90
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27