aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/mb_wrapper.php
blob: 7d49da315bba36b9de8e42ce45ba36743ffb130c (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
<?php

// if mb functions are available, set internal encoding to UTF8
if (is_callable('mb_internal_encoding')) {
	mb_internal_encoding("UTF-8");
}

// map string functions to their mb_str_func alternatives
// and wrap them in elgg_str_fun()

// list of non-mb safe string functions to wrap in elgg_*()
// only will work with mb_* functions that take the same
// params in the same order as their non-mb safe counterparts.
$str_funcs = array(
	'parse_str',
	'split',
	'stristr',
	'strlen',
	'strpos',
	'strrchr',
	'strripos',
	'strrpos',
	'strstr',
	'strtolower',
	'strtoupper',
	'substr_count',
	'substr'
);

$eval_statement = '';
foreach ($str_funcs as $func) {
	// create wrapper function passing in the same args as given
	$eval_statement .= "
	function elgg_$func() {
		\$args = func_get_args();
		if (is_callable('$mb_func')) {
			return call_user_func_array('$mb_func', \$args);
		}
		return call_user_func_array('$func', \$args);
	}
";
}

// TODO: Other wrapper functions