Assuming that in 2019 every solution which is not UNICODE-safe is wrong. What is the best way to convert a string to array of UNICODE characters in PHP?
Obviously this means that accessing the bytes with the brace syntax is wrong, as well as using str_split
:
$arr = str_split($text);
From sample input like:
$string = '先ée?€??????? ????????';
I expect:
array(16) {
[0]=>
string(3) "先"
[1]=>
string(2) "é"
[2]=>
string(1) "e"
[3]=>
string(2) "?"
[4]=>
string(3) "€"
[5]=>
string(4) "??"
[6]=>
string(4) "??"
[7]=>
string(4) "??"
[8]=>
string(3) "?"
[9]=>
string(1) " "
[10]=>
string(4) "??"
[11]=>
string(3) "?"
[12]=>
string(3) "?"
[13]=>
string(3) "?"
[14]=>
string(3) "?"
[15]=>
string(4) "??"
}
See Question&Answers more detail:os