1 <?php
2 /**
3 * @package utf8
4 */
5
6 //---------------------------------------------------------------
7 /**
8 * UTF-8 aware alternative to str_split
9 * Convert a string to an array
10 * Note: requires utf8_strlen to be loaded
11 * @param string UTF-8 encoded
12 * @param int number to characters to split string by
13 * @return string characters in string reverses
14 * @see http://www.php.net/str_split
15 * @see utf8_strlen
16 * @package utf8
17 */
18 function utf8_str_split($str, $split_len = 1) {
19
20 if ( !preg_match('/^[0-9]+$/',$split_len) || $split_len < 1 ) {
21 return FALSE;
22 }
23
24 $len = utf8_strlen($str);
25 if ( $len <= $split_len ) {
26 return array($str);
27 }
28
29 preg_match_all('/.{'.$split_len.'}|[^\x00]{1,'.$split_len.'}$/us', $str, $ar);
30 return $ar[0];
31
32 }
33