aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/mb_wrapper.php
blob: 411a2d5c2e6a1ada0adcb7a9bd4ebf8e34afb2d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
	/**
	 * Elgg wrapper functions for multibyte string support.
	 * 
	 * @package Elgg
	 * @subpackage Core
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author Curverider Ltd
	 * @copyright Curverider Ltd 2008-2009
	 * @link http://elgg.org/
	 */

	/**
	 * Wrapper function: Returns the result of mb_strtolower if mb_support is present, else the
	 * result of strtolower is returned.
	 *
	 * @param string $string The string.
	 * @param string $charset The charset (if multibyte support is present) : default 'UTF8'
	 * @return string
	 */
	function elgg_strtolower($string, $charset = 'UTF8')
	{
		if (is_callable('mb_strtolower'))
			return mb_strtolower($string, $charset);
			
		return strtolower($string);
	}
	
	/**
	 * Wrapper function: Returns the result of mb_strtoupper if mb_support is present, else the
	 * result of strtoupper is returned.
	 *
	 * @param string $string The string.
	 * @param string $charset The charset (if multibyte support is present) : default 'UTF8'
	 * @return string
	 */
	function elgg_strtoupper($string, $charset = 'UTF8')
	{
		if (is_callable('mb_strtoupper'))
			return mb_strtoupper($string, $charset);
			
		return strtoupper($string);
	}
	
	/**
	 * Wrapper function: Returns the result of mb_substr if mb_support is present, else the 
	 * result of substr is returned.
	 *
	 * @param string $string The string.
	 * @param int $start Start position.
	 * @param int $length Length.
	 * @param string $charset The charset (if multibyte support is present) : default 'UTF8'
	 * @return string
	 */
	function elgg_substr($string, $start = 0, $length = null, $charset = 'UTF8')
	{
		if (is_callable('mb_substr'))
			return mb_substr($string, $start, $length, $charset);
		
		return substr($string, $start, $length);
	}
	
	// TODO: Other wrapper functions
?>