Trying to split this string "主楼怎么走" into separate characters (I need an array) using mb_split with no luck... Any suggestions?
Thank you!
Trying to split this string "主楼怎么走" into separate characters (I need an array) using mb_split with no luck... Any suggestions?
Thank you!
An ugly way to do it is:
mb_internal_encoding("UTF-8"); // this IS A MUST!! PHP has trouble with multibyte
// when no internal encoding is set!
$string = ".....";
$chars = array();
for ($i = 0; $i < mb_strlen($string); $i++ ) {
$chars[] = mb_substr($string, $i, 1); // only one char to go to the array
}
You should also try your way with mb_split with setting the internal_encoding before it.
I would use str_split() for that.
$string = "主楼怎么走";
$array = str_split($string);
echo $array[0]; // would output 主
try a regular expression with 'u' option, for example
$chars = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
Thanks for mb_internal_encoding("utf-8"); function and mb_substr() and mb_split() thanks alot