30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
35 require(PHPEXCEL_ROOT .
'PHPExcel/Autoloader.php');
51 if (ord($c{0}) >=0 && ord($c{0}) <= 127)
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)
77 if ((!is_numeric($character)) || ($character < 0)) {
81 if (function_exists(
'mb_convert_encoding')) {
82 return mb_convert_encoding(
'&#'.intval($character).
';',
'UTF-8',
'HTML-ENTITIES');
84 return chr(intval($character));
98 if (is_bool($stringValue)) {
99 $stringValue = ($stringValue) ?
'TRUE' :
'FALSE';
102 if (self::$_invalidChars == Null) {
103 self::$_invalidChars = range(chr(0),chr(31));
106 if (is_string($stringValue) || is_numeric($stringValue)) {
107 return str_replace(self::$_invalidChars,
'',trim($stringValue,
"\x00..\x1F"));
122 if (is_string($stringValue) || is_numeric($stringValue)) {
123 return trim(preg_replace(
'/ +/',
' ',$stringValue));
137 if (is_bool($characters)) {
139 $characters = (int) $characters;
142 $characters =
'True';
144 $characters =
'False';
149 $character = $characters;
150 if ((function_exists(
'mb_strlen')) && (function_exists(
'mb_substr'))) {
151 if (mb_strlen($characters,
'UTF-8') > 1) { $character = mb_substr($characters, 0, 1,
'UTF-8'); }
154 if (strlen($characters) > 0) { $character = substr($characters, 0, 1); }
155 return ord($character);
171 foreach ($aArgs as
$arg) {
183 $returnValue .=
$arg;
203 public static function DOLLAR($value = 0, $decimals = 2) {
208 if (!is_numeric($value) || !is_numeric($decimals)) {
211 $decimals = floor($decimals);
214 return money_format(
'%.'.$decimals.
'n',$value);
216 $round = pow(10,abs($decimals));
217 if ($value < 0) { $round = 0-$round; }
221 return substr(money_format(
'%.1n',$value),0,-2);
239 if (!is_bool($needle)) {
240 if (is_bool($haystack)) {
241 $haystack = ($haystack) ?
'TRUE' :
'FALSE';
244 if (($offset > 0) && (strlen($haystack) > $offset)) {
245 if (function_exists(
'mb_strpos')) {
246 $pos = mb_strpos($haystack, $needle, --$offset,
'UTF-8');
248 $pos = strpos($haystack, $needle, --$offset);
250 if (
$pos !==
false) {
272 if (!is_bool($needle)) {
273 if (is_bool($haystack)) {
274 $haystack = ($haystack) ?
'TRUE' :
'FALSE';
277 if (($offset > 0) && (strlen($haystack) > $offset)) {
278 if (function_exists(
'mb_stripos')) {
279 $pos = mb_stripos($haystack, $needle, --$offset,
'UTF-8');
281 $pos = stripos($haystack, $needle, --$offset);
283 if (
$pos !==
false) {
298 public static function FIXEDFORMAT($value,$decimals=2,$no_commas=
false) {
303 $valueResult = round($value,$decimals);
304 if ($decimals < 0) { $decimals = 0; }
306 $valueResult = number_format($valueResult,$decimals);
309 return (
string) $valueResult;
320 public static function LEFT($value =
'', $chars = 1) {
328 if (is_bool($value)) {
329 $value = ($value) ?
'TRUE' :
'FALSE';
332 if (function_exists(
'mb_substr')) {
333 return mb_substr($value, 0, $chars,
'UTF-8');
335 return substr($value, 0, $chars);
348 public static function MID($value =
'', $start = 1, $chars = null) {
353 if (($start < 1) || ($chars < 0)) {
357 if (is_bool($value)) {
358 $value = ($value) ?
'TRUE' :
'FALSE';
361 if (function_exists(
'mb_substr')) {
362 return mb_substr($value, --$start, $chars,
'UTF-8');
364 return substr($value, --$start, $chars);
376 public static function RIGHT($value =
'', $chars = 1) {
384 if (is_bool($value)) {
385 $value = ($value) ?
'TRUE' :
'FALSE';
388 if ((function_exists(
'mb_substr')) && (function_exists(
'mb_strlen'))) {
389 return mb_substr($value, mb_strlen($value,
'UTF-8') - $chars, $chars,
'UTF-8');
391 return substr($value, strlen($value) - $chars);
406 if (is_bool($value)) {
407 $value = ($value) ?
'TRUE' :
'FALSE';
410 if (function_exists(
'mb_strlen')) {
411 return mb_strlen($value,
'UTF-8');
413 return strlen($value);
429 if (is_bool($mixedCaseString)) {
430 $mixedCaseString = ($mixedCaseString) ?
'TRUE' :
'FALSE';
433 if (function_exists(
'mb_convert_case')) {
434 return mb_convert_case($mixedCaseString, MB_CASE_LOWER,
'UTF-8');
436 return strtoupper($mixedCaseString);
452 if (is_bool($mixedCaseString)) {
453 $mixedCaseString = ($mixedCaseString) ?
'TRUE' :
'FALSE';
456 if (function_exists(
'mb_convert_case')) {
457 return mb_convert_case($mixedCaseString, MB_CASE_UPPER,
'UTF-8');
459 return strtoupper($mixedCaseString);
475 if (is_bool($mixedCaseString)) {
476 $mixedCaseString = ($mixedCaseString) ?
'TRUE' :
'FALSE';
479 if (function_exists(
'mb_convert_case')) {
480 return mb_convert_case($mixedCaseString, MB_CASE_TITLE,
'UTF-8');
482 return ucwords($mixedCaseString);
495 public static function REPLACE($oldText =
'', $start = 1, $chars = null, $newText) {
502 $right =
self::RIGHT($oldText,self::STRINGLENGTH($oldText)-($start+$chars)+1);
504 return $left.$newText.$right;
517 public static function SUBSTITUTE($text =
'', $fromText =
'', $toText =
'', $instance = 0) {
523 if ($instance == 0) {
524 if(function_exists(
'mb_str_replace')) {
525 return mb_str_replace($fromText,$toText,$text);
527 return str_replace($fromText,$toText,$text);
531 while($instance > 0) {
532 if (function_exists(
'mb_strpos')) {
533 $pos = mb_strpos($text, $fromText,
$pos+1,
'UTF-8');
535 $pos = strpos($text, $fromText,
$pos+1);
537 if (
$pos ===
false) {
542 if (
$pos !==
false) {
543 if (function_exists(
'mb_strlen')) {
551 return $left.$newText.$right;
564 if (is_string($testValue)) {