To split by mb letters, use preg_split with /u modifier instead of calling mb functions thousand times.
mb_split
(PHP 4 >= 4.2.0, PHP 5)
mb_split — Split multibyte string using regular expression
說明
array mb_split
( string $pattern
, string $string
[,
int $limit
] )
mb_split() split multibyte string using regular expression pattern and returns the result as an array.
If optional parameter limit is specified, it will be split in limit elements as maximum.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
See also: mb_regex_encoding(), mb_ereg().
mb_split
Sezer Yalcin
19-Feb-2009 01:13
19-Feb-2009 01:13
adjwilli at yahoo dot com
26-Dec-2007 05:37
26-Dec-2007 05:37
I figure most people will want a simple way to break-up a multibyte string into its individual characters. Here's a function I'm using to do that. Change UTF-8 to your chosen encoding method.
function mbStringToArray ($string) {
$strlen = mb_strlen($string);
while ($strlen) {
$array[] = mb_substr($string,0,1,"UTF-8");
$string = mb_substr($string,1,$strlen,"UTF-8");
$strlen = mb_strlen($string);
}
return $array;
}
