Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2388 jpm 1
<?php
2
/**
3
 * PHPExcel
4
 *
5
 * Copyright (c) 2006 - 2013 PHPExcel
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 *
21
 * @category	PHPExcel
22
 * @package		PHPExcel_Calculation
23
 * @copyright	Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
24
 * @license		http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
25
 * @version		##VERSION##, ##DATE##
26
 */
27
 
28
 
29
/** PHPExcel root directory */
30
if (!defined('PHPEXCEL_ROOT')) {
31
	/**
32
	 * @ignore
33
	 */
34
	define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35
	require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36
}
37
 
38
 
39
/** MAX_VALUE */
40
define('MAX_VALUE', 1.2e308);
41
 
42
/** 2 / PI */
43
define('M_2DIVPI', 0.63661977236758134307553505349006);
44
 
45
/** MAX_ITERATIONS */
46
define('MAX_ITERATIONS', 256);
47
 
48
/** PRECISION */
49
define('PRECISION', 8.88E-016);
50
 
51
 
52
/**
53
 * PHPExcel_Calculation_Functions
54
 *
55
 * @category	PHPExcel
56
 * @package		PHPExcel_Calculation
57
 * @copyright	Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
58
 */
59
class PHPExcel_Calculation_Functions {
60
 
61
	/** constants */
62
	const COMPATIBILITY_EXCEL		= 'Excel';
63
	const COMPATIBILITY_GNUMERIC	= 'Gnumeric';
64
	const COMPATIBILITY_OPENOFFICE	= 'OpenOfficeCalc';
65
 
66
	const RETURNDATE_PHP_NUMERIC	= 'P';
67
	const RETURNDATE_PHP_OBJECT		= 'O';
68
	const RETURNDATE_EXCEL			= 'E';
69
 
70
 
71
	/**
72
	 * Compatibility mode to use for error checking and responses
73
	 *
74
	 * @access	private
75
	 * @var string
76
	 */
77
	protected static $compatibilityMode	= self::COMPATIBILITY_EXCEL;
78
 
79
	/**
80
	 * Data Type to use when returning date values
81
	 *
82
	 * @access	private
83
	 * @var string
84
	 */
85
	protected static $ReturnDateType	= self::RETURNDATE_EXCEL;
86
 
87
	/**
88
	 * List of error codes
89
	 *
90
	 * @access	private
91
	 * @var array
92
	 */
93
	protected static $_errorCodes	= array( 'null'				=> '#NULL!',
94
											 'divisionbyzero'	=> '#DIV/0!',
95
											 'value'			=> '#VALUE!',
96
											 'reference'		=> '#REF!',
97
											 'name'				=> '#NAME?',
98
											 'num'				=> '#NUM!',
99
											 'na'				=> '#N/A',
100
											 'gettingdata'		=> '#GETTING_DATA'
101
										   );
102
 
103
 
104
	/**
105
	 * Set the Compatibility Mode
106
	 *
107
	 * @access	public
108
	 * @category Function Configuration
109
	 * @param	 string		$compatibilityMode		Compatibility Mode
110
	 *												Permitted values are:
111
	 *													PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL			'Excel'
112
	 *													PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC		'Gnumeric'
113
	 *													PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE	'OpenOfficeCalc'
114
	 * @return	 boolean	(Success or Failure)
115
	 */
116
	public static function setCompatibilityMode($compatibilityMode) {
117
		if (($compatibilityMode == self::COMPATIBILITY_EXCEL) ||
118
			($compatibilityMode == self::COMPATIBILITY_GNUMERIC) ||
119
			($compatibilityMode == self::COMPATIBILITY_OPENOFFICE)) {
120
			self::$compatibilityMode = $compatibilityMode;
121
			return True;
122
		}
123
		return False;
124
	}	//	function setCompatibilityMode()
125
 
126
 
127
	/**
128
	 * Return the current Compatibility Mode
129
	 *
130
	 * @access	public
131
	 * @category Function Configuration
132
	 * @return	 string		Compatibility Mode
133
	 *							Possible Return values are:
134
	 *								PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL			'Excel'
135
	 *								PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC		'Gnumeric'
136
	 *								PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE	'OpenOfficeCalc'
137
	 */
138
	public static function getCompatibilityMode() {
139
		return self::$compatibilityMode;
140
	}	//	function getCompatibilityMode()
141
 
142
 
143
	/**
144
	 * Set the Return Date Format used by functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object)
145
	 *
146
	 * @access	public
147
	 * @category Function Configuration
148
	 * @param	 string	$returnDateType			Return Date Format
149
	 *												Permitted values are:
150
	 *													PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC		'P'
151
	 *													PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT		'O'
152
	 *													PHPExcel_Calculation_Functions::RETURNDATE_EXCEL			'E'
153
	 * @return	 boolean							Success or failure
154
	 */
155
	public static function setReturnDateType($returnDateType) {
156
		if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) ||
157
			($returnDateType == self::RETURNDATE_PHP_OBJECT) ||
158
			($returnDateType == self::RETURNDATE_EXCEL)) {
159
			self::$ReturnDateType = $returnDateType;
160
			return True;
161
		}
162
		return False;
163
	}	//	function setReturnDateType()
164
 
165
 
166
	/**
167
	 * Return the current Return Date Format for functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object)
168
	 *
169
	 * @access	public
170
	 * @category Function Configuration
171
	 * @return	 string		Return Date Format
172
	 *							Possible Return values are:
173
	 *								PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC		'P'
174
	 *								PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT		'O'
175
	 *								PHPExcel_Calculation_Functions::RETURNDATE_EXCEL			'E'
176
	 */
177
	public static function getReturnDateType() {
178
		return self::$ReturnDateType;
179
	}	//	function getReturnDateType()
180
 
181
 
182
	/**
183
	 * DUMMY
184
	 *
185
	 * @access	public
186
	 * @category Error Returns
187
	 * @return	string	#Not Yet Implemented
188
	 */
189
	public static function DUMMY() {
190
		return '#Not Yet Implemented';
191
	}	//	function DUMMY()
192
 
193
 
194
	/**
195
	 * DIV0
196
	 *
197
	 * @access	public
198
	 * @category Error Returns
199
	 * @return	string	#Not Yet Implemented
200
	 */
201
	public static function DIV0() {
202
		return self::$_errorCodes['divisionbyzero'];
203
	}	//	function DIV0()
204
 
205
 
206
	/**
207
	 * NA
208
	 *
209
	 * Excel Function:
210
	 *		=NA()
211
	 *
212
	 * Returns the error value #N/A
213
	 *		#N/A is the error value that means "no value is available."
214
	 *
215
	 * @access	public
216
	 * @category Logical Functions
217
	 * @return	string	#N/A!
218
	 */
219
	public static function NA() {
220
		return self::$_errorCodes['na'];
221
	}	//	function NA()
222
 
223
 
224
	/**
225
	 * NaN
226
	 *
227
	 * Returns the error value #NUM!
228
	 *
229
	 * @access	public
230
	 * @category Error Returns
231
	 * @return	string	#NUM!
232
	 */
233
	public static function NaN() {
234
		return self::$_errorCodes['num'];
235
	}	//	function NaN()
236
 
237
 
238
	/**
239
	 * NAME
240
	 *
241
	 * Returns the error value #NAME?
242
	 *
243
	 * @access	public
244
	 * @category Error Returns
245
	 * @return	string	#NAME?
246
	 */
247
	public static function NAME() {
248
		return self::$_errorCodes['name'];
249
	}	//	function NAME()
250
 
251
 
252
	/**
253
	 * REF
254
	 *
255
	 * Returns the error value #REF!
256
	 *
257
	 * @access	public
258
	 * @category Error Returns
259
	 * @return	string	#REF!
260
	 */
261
	public static function REF() {
262
		return self::$_errorCodes['reference'];
263
	}	//	function REF()
264
 
265
 
266
	/**
267
	 * NULL
268
	 *
269
	 * Returns the error value #NULL!
270
	 *
271
	 * @access	public
272
	 * @category Error Returns
273
	 * @return	string	#REF!
274
	 */
275
	public static function NULL() {
276
		return self::$_errorCodes['null'];
277
	}	//	function NULL()
278
 
279
 
280
	/**
281
	 * VALUE
282
	 *
283
	 * Returns the error value #VALUE!
284
	 *
285
	 * @access	public
286
	 * @category Error Returns
287
	 * @return	string	#VALUE!
288
	 */
289
	public static function VALUE() {
290
		return self::$_errorCodes['value'];
291
	}	//	function VALUE()
292
 
293
 
294
	public static function isMatrixValue($idx) {
295
		return ((substr_count($idx,'.') <= 1) || (preg_match('/\.[A-Z]/',$idx) > 0));
296
	}
297
 
298
 
299
	public static function isValue($idx) {
300
		return (substr_count($idx,'.') == 0);
301
	}
302
 
303
 
304
	public static function isCellValue($idx) {
305
		return (substr_count($idx,'.') > 1);
306
	}
307
 
308
 
309
	public static function _ifCondition($condition) {
310
		$condition	= PHPExcel_Calculation_Functions::flattenSingleValue($condition);
311
		if (!isset($condition{0}))
312
			$condition = '=""';
313
		if (!in_array($condition{0},array('>', '<', '='))) {
314
			if (!is_numeric($condition)) { $condition = PHPExcel_Calculation::_wrapResult(strtoupper($condition)); }
315
			return '='.$condition;
316
		} else {
317
			preg_match('/([<>=]+)(.*)/',$condition,$matches);
318
			list(,$operator,$operand) = $matches;
319
			if (!is_numeric($operand)) { $operand = PHPExcel_Calculation::_wrapResult(strtoupper($operand)); }
320
			return $operator.$operand;
321
		}
322
	}	//	function _ifCondition()
323
 
324
 
325
	/**
326
	 * ERROR_TYPE
327
	 *
328
	 * @param	mixed	$value	Value to check
329
	 * @return	boolean
330
	 */
331
	public static function ERROR_TYPE($value = '') {
332
		$value	= self::flattenSingleValue($value);
333
 
334
		$i = 1;
335
		foreach(self::$_errorCodes as $errorCode) {
336
			if ($value === $errorCode) {
337
				return $i;
338
			}
339
			++$i;
340
		}
341
		return self::NA();
342
	}	//	function ERROR_TYPE()
343
 
344
 
345
	/**
346
	 * IS_BLANK
347
	 *
348
	 * @param	mixed	$value	Value to check
349
	 * @return	boolean
350
	 */
351
	public static function IS_BLANK($value = NULL) {
352
		if (!is_null($value)) {
353
			$value	= self::flattenSingleValue($value);
354
		}
355
 
356
		return is_null($value);
357
	}	//	function IS_BLANK()
358
 
359
 
360
	/**
361
	 * IS_ERR
362
	 *
363
	 * @param	mixed	$value	Value to check
364
	 * @return	boolean
365
	 */
366
	public static function IS_ERR($value = '') {
367
		$value		= self::flattenSingleValue($value);
368
 
369
		return self::IS_ERROR($value) && (!self::IS_NA($value));
370
	}	//	function IS_ERR()
371
 
372
 
373
	/**
374
	 * IS_ERROR
375
	 *
376
	 * @param	mixed	$value	Value to check
377
	 * @return	boolean
378
	 */
379
	public static function IS_ERROR($value = '') {
380
		$value		= self::flattenSingleValue($value);
381
 
382
		if (!is_string($value))
383
			return false;
384
		return in_array($value, array_values(self::$_errorCodes));
385
	}	//	function IS_ERROR()
386
 
387
 
388
	/**
389
	 * IS_NA
390
	 *
391
	 * @param	mixed	$value	Value to check
392
	 * @return	boolean
393
	 */
394
	public static function IS_NA($value = '') {
395
		$value		= self::flattenSingleValue($value);
396
 
397
		return ($value === self::NA());
398
	}	//	function IS_NA()
399
 
400
 
401
	/**
402
	 * IS_EVEN
403
	 *
404
	 * @param	mixed	$value	Value to check
405
	 * @return	boolean
406
	 */
407
	public static function IS_EVEN($value = NULL) {
408
		$value = self::flattenSingleValue($value);
409
 
410
		if ($value === NULL)
411
			return self::NAME();
412
		if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value))))
413
			return self::VALUE();
414
		return ($value % 2 == 0);
415
	}	//	function IS_EVEN()
416
 
417
 
418
	/**
419
	 * IS_ODD
420
	 *
421
	 * @param	mixed	$value	Value to check
422
	 * @return	boolean
423
	 */
424
	public static function IS_ODD($value = NULL) {
425
		$value = self::flattenSingleValue($value);
426
 
427
		if ($value === NULL)
428
			return self::NAME();
429
		if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value))))
430
			return self::VALUE();
431
		return (abs($value) % 2 == 1);
432
	}	//	function IS_ODD()
433
 
434
 
435
	/**
436
	 * IS_NUMBER
437
	 *
438
	 * @param	mixed	$value		Value to check
439
	 * @return	boolean
440
	 */
441
	public static function IS_NUMBER($value = NULL) {
442
		$value		= self::flattenSingleValue($value);
443
 
444
		if (is_string($value)) {
445
			return False;
446
		}
447
		return is_numeric($value);
448
	}	//	function IS_NUMBER()
449
 
450
 
451
	/**
452
	 * IS_LOGICAL
453
	 *
454
	 * @param	mixed	$value		Value to check
455
	 * @return	boolean
456
	 */
457
	public static function IS_LOGICAL($value = NULL) {
458
		$value		= self::flattenSingleValue($value);
459
 
460
		return is_bool($value);
461
	}	//	function IS_LOGICAL()
462
 
463
 
464
	/**
465
	 * IS_TEXT
466
	 *
467
	 * @param	mixed	$value		Value to check
468
	 * @return	boolean
469
	 */
470
	public static function IS_TEXT($value = NULL) {
471
		$value		= self::flattenSingleValue($value);
472
 
473
		return (is_string($value) && !self::IS_ERROR($value));
474
	}	//	function IS_TEXT()
475
 
476
 
477
	/**
478
	 * IS_NONTEXT
479
	 *
480
	 * @param	mixed	$value		Value to check
481
	 * @return	boolean
482
	 */
483
	public static function IS_NONTEXT($value = NULL) {
484
		return !self::IS_TEXT($value);
485
	}	//	function IS_NONTEXT()
486
 
487
 
488
	/**
489
	 * VERSION
490
	 *
491
	 * @return	string	Version information
492
	 */
493
	public static function VERSION() {
494
		return 'PHPExcel ##VERSION##, ##DATE##';
495
	}	//	function VERSION()
496
 
497
 
498
	/**
499
	 * N
500
	 *
501
	 * Returns a value converted to a number
502
	 *
503
	 * @param	value		The value you want converted
504
	 * @return	number		N converts values listed in the following table
505
	 *		If value is or refers to N returns
506
	 *		A number			That number
507
	 *		A date				The serial number of that date
508
	 *		TRUE				1
509
	 *		FALSE				0
510
	 *		An error value		The error value
511
	 *		Anything else		0
512
	 */
513
	public static function N($value = NULL) {
514
		while (is_array($value)) {
515
			$value = array_shift($value);
516
		}
517
 
518
		switch (gettype($value)) {
519
			case 'double'	:
520
			case 'float'	:
521
			case 'integer'	:
522
				return $value;
523
				break;
524
			case 'boolean'	:
525
				return (integer) $value;
526
				break;
527
			case 'string'	:
528
				//	Errors
529
				if ((strlen($value) > 0) && ($value{0} == '#')) {
530
					return $value;
531
				}
532
				break;
533
		}
534
		return 0;
535
	}	//	function N()
536
 
537
 
538
	/**
539
	 * TYPE
540
	 *
541
	 * Returns a number that identifies the type of a value
542
	 *
543
	 * @param	value		The value you want tested
544
	 * @return	number		N converts values listed in the following table
545
	 *		If value is or refers to N returns
546
	 *		A number			1
547
	 *		Text				2
548
	 *		Logical Value		4
549
	 *		An error value		16
550
	 *		Array or Matrix		64
551
	 */
552
	public static function TYPE($value = NULL) {
553
		$value	= self::flattenArrayIndexed($value);
554
		if (is_array($value) && (count($value) > 1)) {
555
			$a = array_keys($value);
556
			$a = array_pop($a);
557
			//	Range of cells is an error
558
			if (self::isCellValue($a)) {
559
				return 16;
560
			//	Test for Matrix
561
			} elseif (self::isMatrixValue($a)) {
562
				return 64;
563
			}
564
		} elseif(empty($value)) {
565
			//	Empty Cell
566
			return 1;
567
		}
568
		$value	= self::flattenSingleValue($value);
569
 
570
		if (($value === NULL) || (is_float($value)) || (is_int($value))) {
571
				return 1;
572
		} elseif(is_bool($value)) {
573
				return 4;
574
		} elseif(is_array($value)) {
575
				return 64;
576
				break;
577
		} elseif(is_string($value)) {
578
			//	Errors
579
			if ((strlen($value) > 0) && ($value{0} == '#')) {
580
				return 16;
581
			}
582
			return 2;
583
		}
584
		return 0;
585
	}	//	function TYPE()
586
 
587
 
588
	/**
589
	 * Convert a multi-dimensional array to a simple 1-dimensional array
590
	 *
591
	 * @param	array	$array	Array to be flattened
592
	 * @return	array	Flattened array
593
	 */
594
	public static function flattenArray($array) {
595
		if (!is_array($array)) {
596
			return (array) $array;
597
		}
598
 
599
		$arrayValues = array();
600
		foreach ($array as $value) {
601
			if (is_array($value)) {
602
				foreach ($value as $val) {
603
					if (is_array($val)) {
604
						foreach ($val as $v) {
605
							$arrayValues[] = $v;
606
						}
607
					} else {
608
						$arrayValues[] = $val;
609
					}
610
				}
611
			} else {
612
				$arrayValues[] = $value;
613
			}
614
		}
615
 
616
		return $arrayValues;
617
	}	//	function flattenArray()
618
 
619
 
620
	/**
621
	 * Convert a multi-dimensional array to a simple 1-dimensional array, but retain an element of indexing
622
	 *
623
	 * @param	array	$array	Array to be flattened
624
	 * @return	array	Flattened array
625
	 */
626
	public static function flattenArrayIndexed($array) {
627
		if (!is_array($array)) {
628
			return (array) $array;
629
		}
630
 
631
		$arrayValues = array();
632
		foreach ($array as $k1 => $value) {
633
			if (is_array($value)) {
634
				foreach ($value as $k2 => $val) {
635
					if (is_array($val)) {
636
						foreach ($val as $k3 => $v) {
637
							$arrayValues[$k1.'.'.$k2.'.'.$k3] = $v;
638
						}
639
					} else {
640
						$arrayValues[$k1.'.'.$k2] = $val;
641
					}
642
				}
643
			} else {
644
				$arrayValues[$k1] = $value;
645
			}
646
		}
647
 
648
		return $arrayValues;
649
	}	//	function flattenArrayIndexed()
650
 
651
 
652
	/**
653
	 * Convert an array to a single scalar value by extracting the first element
654
	 *
655
	 * @param	mixed		$value		Array or scalar value
656
	 * @return	mixed
657
	 */
658
	public static function flattenSingleValue($value = '') {
659
		while (is_array($value)) {
660
			$value = array_pop($value);
661
		}
662
 
663
		return $value;
664
	}	//	function flattenSingleValue()
665
 
666
}	//	class PHPExcel_Calculation_Functions
667
 
668
 
669
//
670
//	There are a few mathematical functions that aren't available on all versions of PHP for all platforms
671
//	These functions aren't available in Windows implementations of PHP prior to version 5.3.0
672
//	So we test if they do exist for this version of PHP/operating platform; and if not we create them
673
//
674
if (!function_exists('acosh')) {
675
	function acosh($x) {
676
		return 2 * log(sqrt(($x + 1) / 2) + sqrt(($x - 1) / 2));
677
	}	//	function acosh()
678
}
679
 
680
if (!function_exists('asinh')) {
681
	function asinh($x) {
682
		return log($x + sqrt(1 + $x * $x));
683
	}	//	function asinh()
684
}
685
 
686
if (!function_exists('atanh')) {
687
	function atanh($x) {
688
		return (log(1 + $x) - log(1 - $x)) / 2;
689
	}	//	function atanh()
690
}
691
 
692
if (!function_exists('money_format')) {
693
	function money_format($format, $number) {
694
		$regex = array( '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?(?:#([0-9]+))?',
695
						 '(?:\.([0-9]+))?([in%])/'
696
					  );
697
		$regex = implode('', $regex);
698
		if (setlocale(LC_MONETARY, null) == '') {
699
			setlocale(LC_MONETARY, '');
700
		}
701
		$locale = localeconv();
702
		$number = floatval($number);
703
		if (!preg_match($regex, $format, $fmatch)) {
704
			trigger_error("No format specified or invalid format", E_USER_WARNING);
705
			return $number;
706
		}
707
		$flags = array( 'fillchar'	=> preg_match('/\=(.)/', $fmatch[1], $match) ? $match[1] : ' ',
708
						'nogroup'	=> preg_match('/\^/', $fmatch[1]) > 0,
709
						'usesignal'	=> preg_match('/\+|\(/', $fmatch[1], $match) ? $match[0] : '+',
710
						'nosimbol'	=> preg_match('/\!/', $fmatch[1]) > 0,
711
						'isleft'	=> preg_match('/\-/', $fmatch[1]) > 0
712
					  );
713
		$width	= trim($fmatch[2]) ? (int)$fmatch[2] : 0;
714
		$left	= trim($fmatch[3]) ? (int)$fmatch[3] : 0;
715
		$right	= trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits'];
716
		$conversion = $fmatch[5];
717
		$positive = true;
718
		if ($number < 0) {
719
			$positive = false;
720
			$number *= -1;
721
		}
722
		$letter = $positive ? 'p' : 'n';
723
		$prefix = $suffix = $cprefix = $csuffix = $signal = '';
724
		if (!$positive) {
725
			$signal = $locale['negative_sign'];
726
			switch (true) {
727
				case $locale['n_sign_posn'] == 0 || $flags['usesignal'] == '(':
728
					$prefix = '(';
729
					$suffix = ')';
730
					break;
731
				case $locale['n_sign_posn'] == 1:
732
					$prefix = $signal;
733
					break;
734
				case $locale['n_sign_posn'] == 2:
735
					$suffix = $signal;
736
					break;
737
				case $locale['n_sign_posn'] == 3:
738
					$cprefix = $signal;
739
					break;
740
				case $locale['n_sign_posn'] == 4:
741
					$csuffix = $signal;
742
					break;
743
			}
744
		}
745
		if (!$flags['nosimbol']) {
746
			$currency = $cprefix;
747
			$currency .= ($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']);
748
			$currency .= $csuffix;
749
			$currency = iconv('ISO-8859-1','UTF-8',$currency);
750
		} else {
751
			$currency = '';
752
		}
753
		$space = $locale["{$letter}_sep_by_space"] ? ' ' : '';
754
 
755
		if (!isset($locale['mon_decimal_point']) || empty($locale['mon_decimal_point'])) {
756
			$locale['mon_decimal_point'] = (!isset($locale['decimal_point']) || empty($locale['decimal_point'])) ?
757
											$locale['decimal_point'] :
758
											'.';
759
		}
760
 
761
		$number = number_format($number, $right, $locale['mon_decimal_point'], $flags['nogroup'] ? '' : $locale['mon_thousands_sep'] );
762
		$number = explode($locale['mon_decimal_point'], $number);
763
 
764
		$n = strlen($prefix) + strlen($currency);
765
		if ($left > 0 && $left > $n) {
766
			if ($flags['isleft']) {
767
				$number[0] .= str_repeat($flags['fillchar'], $left - $n);
768
			} else {
769
				$number[0] = str_repeat($flags['fillchar'], $left - $n) . $number[0];
770
			}
771
		}
772
		$number = implode($locale['mon_decimal_point'], $number);
773
		if ($locale["{$letter}_cs_precedes"]) {
774
			$number = $prefix . $currency . $space . $number . $suffix;
775
		} else {
776
			$number = $prefix . $number . $space . $currency . $suffix;
777
		}
778
		if ($width > 0) {
779
			$number = str_pad($number, $width, $flags['fillchar'], $flags['isleft'] ? STR_PAD_RIGHT : STR_PAD_LEFT);
780
		}
781
		$format = str_replace($fmatch[0], $number, $format);
782
		return $format;
783
	}	//	function money_format()
784
}
785
 
786
 
787
//
788
//	Strangely, PHP doesn't have a mb_str_replace multibyte function
789
//	As we'll only ever use this function with UTF-8 characters, we can simply "hard-code" the character set
790
//
791
if ((!function_exists('mb_str_replace')) &&
792
	(function_exists('mb_substr')) && (function_exists('mb_strlen')) && (function_exists('mb_strpos'))) {
793
	function mb_str_replace($search, $replace, $subject) {
794
		if(is_array($subject)) {
795
			$ret = array();
796
			foreach($subject as $key => $val) {
797
				$ret[$key] = mb_str_replace($search, $replace, $val);
798
			}
799
			return $ret;
800
		}
801
 
802
		foreach((array) $search as $key => $s) {
803
			if($s == '') {
804
				continue;
805
			}
806
			$r = !is_array($replace) ? $replace : (array_key_exists($key, $replace) ? $replace[$key] : '');
807
			$pos = mb_strpos($subject, $s, 0, 'UTF-8');
808
			while($pos !== false) {
809
				$subject = mb_substr($subject, 0, $pos, 'UTF-8') . $r . mb_substr($subject, $pos + mb_strlen($s, 'UTF-8'), 65535, 'UTF-8');
810
				$pos = mb_strpos($subject, $s, $pos + mb_strlen($r, 'UTF-8'), 'UTF-8');
811
			}
812
		}
813
		return $subject;
814
	}
815
}